Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.ObjCRuntime;
using System.Drawing;

namespace PageDemo
{
	public class Application
	{
		static void Main (string[] args)
		{
			UIApplication.Main (args, null, "AppDelegate" );
		}
	}

	// The name AppDelegate is referenced in the MainWindow.xib file.
	[Register("AppDelegate")]
	public class AppDelegate : UIApplicationDelegate
	{
		UIWindow window;
		RootViewController viewController;
		CreditsViewController creditsViewController;
		UINavigationController navigationController;
		
		
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			var screenBounds = UIScreen.MainScreen.Bounds;
			window = new UIWindow(screenBounds);
			viewController = new RootViewController(this);
			creditsViewController = new CreditsViewController(this);
			navigationController = new UINavigationController(viewController);
			
			window.AddSubview(navigationController.View);
			window.MakeKeyAndVisible ();
			return true;
		}
		[Export ("Credits")]
		public void Credits()
		{
			navigationController.PushViewController(creditsViewController, true);
		}
		[Export ("Back")]
		public void Back()
		{
			navigationController.PopViewControllerAnimated(true);
		}
		

		// This method is required in iPhoneOS 3.0
		public override void OnActivated (UIApplication application)
		{
		}
	}
	
	public class RootViewController : UIViewController
	{
		UITextView textView;
		UIBarButtonItem credits;
		UISegmentedControl segmentedControl;
		UINavigationController navigationController;
		int page;
		
		public RootViewController (UIApplicationDelegate deleg):base()
		{
			credits = new UIBarButtonItem("Credits", UIBarButtonItemStyle.Plain, deleg, new Selector("Credits"));
			this.NavigationItem.RightBarButtonItem = credits;
			segmentedControl = new UISegmentedControl();
			segmentedControl.Frame = new RectangleF(0, 0, 150,30);
			segmentedControl.InsertSegment("Bunnies1", 0, false);
			segmentedControl.InsertSegment("Ponies", 1, false);
			segmentedControl.AddTarget(this, new Selector("ControlPressed"), UIControlEvent.ValueChanged);
			segmentedControl.ControlStyle = UISegmentedControlStyle.Bar;
			NavigationItem.TitleView = segmentedControl;
			segmentedControl.SelectedSegment = 0;
		}
		
		[Export ("ControlPressed")]
		public void ControlPressed(NSObject obj)
		{
			SetPage();
		}
		
		public void SetPage()
		{
			if (textView == null) return;
			var index = segmentedControl.SelectedSegment;
			if (index == 0) textView.Text = "Bunnies";
			else textView.Text = "Ponnies";
		}
		
		public override void LoadView ()
		{
			base.LoadView ();
			textView = new UITextView(UIScreen.MainScreen.ApplicationFrame);
			textView.Editable = false;
			SetPage();
			View = textView;
		}				
	}
	
	public class CreditsViewController:UITableViewController
	{
		UITextView textView;
		UINavigationController navigationController;
		public CreditsViewController (UIApplicationDelegate deleg):base()
		{
			var back = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, deleg, new Selector("Back"));
			this.NavigationItem.BackBarButtonItem = back;
		}
		
		public override void LoadView ()
		{
			base.LoadView ();
			textView = new UITextView(UIScreen.MainScreen.ApplicationFrame);
			textView.Editable = false;
			textView.Text = "Iphone text text text text text text text";
			View = textView;
		}

	}
}