using System; using MonoTouch.Foundation; using MonoTouch.UIKit; using System.Drawing; namespace delete201205142 { [Register ("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { UIWindow _window; UINavigationController _navCtrl; MyRoot _root; public override bool FinishedLaunching (UIApplication app, NSDictionary options) { _window = new UIWindow (UIScreen.MainScreen.Bounds); _root = new MyRoot (); _navCtrl = new UINavigationController (_root); _window.RootViewController = _navCtrl; _window.MakeKeyAndVisible (); return true; } } public class MyRoot : UIViewController { UIBarButtonItem buttonEdit; EditView _currentEditView; UILabel _label; UILabel _valueLabel; public override void ViewDidLoad () { base.ViewDidLoad (); this.View.BackgroundColor = UIColor.White; this.NavigationItem.HidesBackButton = true; this.buttonEdit = new UIBarButtonItem(UIBarButtonSystemItem.Edit, this.ButtonEdit_Clicked); this.NavigationItem.SetRightBarButtonItem (buttonEdit, true); _label = new UILabel (new RectangleF (20, 20, this.View.Bounds.Width-40, 25)); _label.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _label.Text = "Name"; this.View.AddSubview (_label); _valueLabel = new UILabel (new RectangleF (30, 50, this.View.Bounds.Width-50, 25)); _valueLabel.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; this.View.AddSubview (_valueLabel); } void ButtonEdit_Clicked (object sender, EventArgs e) { _currentEditView = new EditView (); this.NavigationController.PushViewController (_currentEditView, true); } public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); if (_currentEditView != null) { _valueLabel.Text = _currentEditView.NameValue; } } public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) { return true; } } public class EditView : UIViewController { UIBarButtonItem buttonDone; UILabel _label; UITextField _textField; public override void ViewDidLoad () { base.ViewDidLoad (); this.View.BackgroundColor = UIColor.White; this.NavigationItem.HidesBackButton = true; this.buttonDone = new UIBarButtonItem(UIBarButtonSystemItem.Done, this.ButtonDone_Clicked); this.NavigationItem.SetRightBarButtonItem (buttonDone, true); _label = new UILabel (new RectangleF (20, 20, this.View.Bounds.Width-40, 31)); _label.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _label.Text = "Enter Name"; this.View.AddSubview (_label); _textField = new UITextField (new RectangleF (20, 50, this.View.Bounds.Width-40, 25)); _textField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _textField.BorderStyle = UITextBorderStyle.RoundedRect; this.View.AddSubview (_textField); } public string NameValue { get { return _textField.Text; } } void ButtonDone_Clicked (object sender, EventArgs e) { this.NavigationController.PopViewControllerAnimated (true); } public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) { return true; } } }