2017-05-04 80 views
-1

如何爲我的UIViewController中的每個選項卡添加Web視圖?爲UITabBarController中的每個選項卡添加一個webview?

public class TabController: UITabBarController 
{ 
    UIViewController tab1, tab2, tab3, tab4, tab5, tab6, tab7; 

    public TabController() 
    { 
     tab1 = new UIViewController(); 
     tab1.Title = "Test"; 
     tab1.View.BackgroundColor = UIColor.Orange; 



     tab2 = new UIViewController(); 
     tab2.Title = "Test2"; 
     tab2.View.BackgroundColor = UIColor.Orange; 

     tab3 = new UIViewController(); 
     tab3.Title = "Test3"; 
     tab3.View.BackgroundColor = UIColor.Red; 

     tab4 = new UIViewController(); 
     tab4.Title = "Test4"; 
     tab4.View.BackgroundColor = UIColor.Red; 

     tab5 = new UIViewController(); 
     tab5.Title = "Test5"; 
     tab5.View.BackgroundColor = UIColor.Red; 

     tab6 = new UIViewController(); 
     tab6.Title = "Test6"; 
     tab6.View.BackgroundColor = UIColor.Red; 

     tab7 = new UIViewController(); 
     tab7.Title = "Test7"; 
     tab7.View.BackgroundColor = UIColor.Red; 




     var UIViewController = new UIViewController[] { 
          tab1, tab2, tab3, tab4, tab5, tab6, tab7 
    }; 


     tab1.TabBarItem = new UITabBarItem(UITabBarSystemItem.Favorites, 0); 

     ViewControllers = UIViewController; 
    } 
} 

所以對於每個標籤,而不是「tab1.View.BackgroundColor = UIColor.Orange;」,它 應該是: 網頁視圖+標題+鏈接,這樣每個標籤都有一個不同的頁面?

+0

你想做什麼? – KKRocks

+0

對於每個選項卡,它必須有一個網頁視圖,每個網頁視圖都會有一個鏈接和標題,這樣當我點擊一個選項卡時,我們稱它爲Test1(標題),它將打開一個具有特定鏈接的網頁視圖,然後對於其他選項卡也是如此。 – CaptnA

+0

然後在storyboard中拖動viewcontroller - >拖動webview並在appdelegate中使用這個viewcontroller。 – KKRocks

回答

1

最簡單的方法是使用故事板並將視圖控制器類分配給選項卡。但是,如果你想以編程方式做到這一點,我想你需要做到以下幾點:

tab7 = new UIViewController(); 
    tab7.Title = "Test7"; 
    tab7.View.BackgroundColor = UIColor.Red; 
    //Create a webview 
    UIWebView webView = new UIWebView(View.Bounds); //Takes size as a constructor parameter 
    //Set it's navigation location 
    webView.Navigate(new URI("www.whatever.co.uk")); 
    //Add the webview to the subviews of your UIViewController 
    tab7.View.AddSubview(webView); 

你會爲每個標籤做到這一點。

值得一提的是,值得一提的是,應用程序提交給他們的商店的蘋果指南確實傾向於對僅僅是網站表示的應用程序皺眉,所以值得記住這一點。應用程序必須能夠完成比蘋果瀏覽器更多的功能。

+0

剛剛嘗試過,當我聲明UIWebView時,它說「默認構造函數初始化此類的新實例時不帶參數」。 – CaptnA

+0

道歉,我的錯誤,我忘了web視圖的大小作爲它的構造函數的參數,我已經修改了我的答案,所以它現在應該可以正常工作。 – Digitalsa1nt

+0

感謝您的幫助,但在導航,我得到的錯誤「UIWebView」不包含「導航」的定義和「URI」我得到的類型或命名空間'URI'找不到.. ..會嘗試谷歌這些問題現在,但如果你知道解決這些問題的方法,請讓我知道。感謝你目前的幫助! – CaptnA

相關問題