Monotouch中使用UINavigationController

來源:互聯網
上載者:User

1.使用MonoDevelop建立一個Window-based project

2.右鍵點擊解決方案,Add | New File… | iPhone View with Controller,命名為FirstViewController

3.增加另外一個iPhone View with Controller,命名為SecondViewController

4.到目前為止我們有兩個空的視圖(控制器),我們可以在我們的iPhone應用程式中顯示這2個視圖。預設情況下,它們將不會顯示,所以我們需要應用程式增加一個UINavigationController對象,它用來顯示和隱藏這些視圖。 管理一個UIViewController對象的堆棧,它允許你以編程方式顯示指定控制器/視圖。通過XCode可以很容易地添加UINavigationController到應用程式程式。在MonoDevelop的解決方案視窗雙擊MainWindow.xib。開啟後,在“Library”視窗中單擊“Objects”選項卡上,找到“Navigation Controller”項目,拖放到的MainWindow.xib視窗。

5.接下來,從AppDelegate類的引用UINavigationController的對象。 AppDelegate中的CocoaTouch中的一個類,相當於在WPF和Silverlight程式的Application類。為了給UINavigationController一個引用,必須添加一個“outlet”到AppDelegate類。在XCode中增加的outlet,就可以引用UI對象,並在代碼中建立了相應的屬性變數。命名為navController。

6.在FirstViewController與SecondViewController的View中增加一按鈕,按鈕事件控制跳轉的,代碼如下:

事件內代碼

var secondview = new SecondViewController();

this.myButton.TouchUpInside += delegate{

var nc = base.NavigationController;

nc.PushViewController(secondview,true);

}

 

 

作者:Bruce Lee
出處:http://www.cnblogs.com/BruceLee521
本博原創文章著作權歸部落格園和本人共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出作者名稱和原文串連,否則保留追究法律責任的權利。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.