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;
}
}
}