0

我有下面的代碼被稱爲鑑於我的UIViewController裏面viewDidLoad方法。MonoTouch的異步和展示活動指示燈

在appdelegate裏面我有一個UINavigationController,它用這個前面提到的控制器實例化,而UINavigationController放在UITabViewController裏面,而UITabViewController又被指定爲rootviewcontroller。

控制器裏面我做一個異步網絡調用來獲取數據來填充表,如果我使用加載視圖代碼來顯示一個活動的指標我得到的MonoTouch以下警告。

應用預期具有在

public class LoadingView : UIAlertView 
{ 
    private UIActivityIndicatorView _activityView; 

    public void ShowActivity (string title) 
    { 
     Title = title; 

     this.Show(); 
     // Spinner - add after Show() or we have no Bounds. 
     _activityView = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.WhiteLarge); 
     _activityView.Frame = new RectangleF ((Bounds.Width/2) - 15, Bounds.Height - 50, 30, 30); 
     _activityView.StartAnimating(); 
     AddSubview (_activityView); 

    } 

    public void Hide() 
    { 
     DismissWithClickedButtonIndex (0, true); 
    } 
} 

任何指針將受到歡迎應用啓動的端部的根視圖控制器。

編輯:我已經設置了根視圖控制器。

window = new UIWindow (UIScreen.MainScreen.Bounds); 
     window.RootViewController = tabController; 

完整的appDelegate代碼:

public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 
      // create a new window instance based on the screen size 
      window = new UIWindow (UIScreen.MainScreen.Bounds); 

      tabController = new UITabBarController(); 

      jobsNavigationController = new UINavigationController(new JobsController()); 
      jobsNavigationController.NavigationBar.BarStyle = UIBarStyle.Black; 
      jobsNavigationController.TabBarItem.Image = UIImage.FromFile("Images/briefcase.png"); 
      jobsNavigationController.TabBarItem.Title = "Current Positions"; 

      myAccountNavigationController = new UINavigationController(new LoginDialogViewController()); 
      myAccountNavigationController.NavigationBar.BarStyle = UIBarStyle.Black; 
      myAccountNavigationController.TabBarItem.Image = UIImage.FromFile("images/man.png"); 
      myAccountNavigationController.TabBarItem.Title = "My Account"; 

      tabController.SetViewControllers(new UIViewController[] { jobsNavigationController,myAccountNavigationController,new SettingsDialogViewController()},false); 

      window.RootViewController = tabController; 

      // make the window visible 
      window.MakeKeyAndVisible(); 
      return true; 
     } 
+0

,你能否告訴在AppDelegate中的FinishedLaunching方法?這是通常拋出錯誤的地方。在iOS 5中,您需要分配RootViewController,例如:window.RootViewController = MyTabBarController; – Anuj 2012-02-02 22:04:44

+0

現在看看,已經在做你的建議。 – RubbleFord 2012-02-03 06:55:24

+1

請張貼完整的FinishedLaunching()。我最好的猜測是你的tabConroller是NULL。 – Krumelur 2012-02-03 08:43:24

回答

0

要避免此警告(在iOS5中),並保持的iOS 4.x的兼容性,你可以做你的FinishedLaunching方法裏面如下:

if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0)) 
    window.RootViewController = navigation; 
else 
    window.AddSubview (navigation.View); 

查看here獲取更完整的示例。

+0

剛剛試過你的建議仍然得到同樣的問題。 – RubbleFord 2012-02-03 06:56:34

+0

window.RootViewController已經在iOS4中可用,所以這不成問題。 – Krumelur 2012-02-03 08:39:48

+0

@Krumelur IIRC Apple顯示只在iOS5 +上發出警告(問題),但是你說得對,它自從iOS4開始就已經可用了,所以你可以簡單地將它分配給它,而無需任何條件。 – poupou 2012-02-03 12:47:47

0

window.AddSubview(tabcontroller.view);

修正了問題,奇我不設置RootViewController的了。