我已经在我的UIViewController里面的viewdidload方法中调用了以下代码。
在appdelegate中我有一个UINavigationController,它用上面提到的控制器实例化,然后UINavigationController被放在一个UITabViewController中,而UITabViewController又被指定为rootviewcontroller。
在控制器内我正在进行异步Web调用以获取数据来填充表,如果我使用加载视图代码来显示活动指示器,我会在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 :(得分:0)
要避免此警告(在iOS5中)并保持iOS 4.x兼容性,您可以在FinishedLaunching
方法中执行以下操作:
if (UIDevice.CurrentDevice.CheckSystemVersion (5, 0))
window.RootViewController = navigation;
else
window.AddSubview (navigation.View);
查看here以获取更完整的样本。
答案 1 :(得分:0)
window.AddSubview(tabcontroller.view);
解决了这个问题,奇怪的是我不再设置rootviewcontroller了。