我在AppDelegate中以编程方式创建了一个UITabBarController。我还创建了两个UINavigationController,里面有一些UIViewControllers。我将导航控制器添加到UITabBarController上,如下所示:
BVMapViewController *mapViewController = [[[BVMapViewController alloc] initWithNibName:@"BVMapViewController_iPhone" bundle:nil] autorelease];
BVFavoritesViewController *favoritesViewController = [[[BVFavoritesViewController alloc] initWithNibName:@"BVFavoritesViewController_iPhone" bundle:nil] autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:mapViewController] autorelease];
[navigationController setToolbarHidden:YES];
UINavigationController *navigationControllerForFavorites = [[[UINavigationController alloc] initWithRootViewController:favoritesViewController] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
NSArray* controllers = [NSArray arrayWithObjects:navigationController, navigationControllerForFavorites, nil];
self.tabBarController.viewControllers = controllers;
[self.window setRootViewController:self.tabBarController];
结果可以正确创建带有两个导航控制器的标签栏控制器。
问题如下: 第一个UINavigationController包含一个UIViewController,里面有一个MKMapView。该地图显示了一堆POI,因此当您点击其中一个时,应用程序会向web服务(在后台)发送请求,该请求一旦完成就会通知视图控制器推送另一个UIViewController进入导航堆栈以显示有关该POI的更多信息,
[self.navigationController pushViewController:self.stationViewController
animated:YES];
这里我收到以下错误:
_WebTryThreadLock(bool),0x11d9b560:试图从主线程或Web线程以外的线程获取Web锁。这可能是从辅助线程调用UIKit的结果。现在崩溃...... 1 0x58a76a9 WebThreadLock 2 0x5bfdfe - [UITextView _updateForNewSize:withOldSize:] 3 0x5c00b4 - [UITextView setFrame:] 4 0x4c59df UIViewCommonInitWithFrame 5 0x4c5bae - [UIView initWithCoder:] 6 0x4d9fb7 - [UIScrollView initWithCoder:] 7 0x5bc851 - [UITextView initWithCoder:] 8 0x7b1a02 UINibDecoderDecodeObjectForValue 9 0x7b10e5 - [UINibDecoder decodeObjectForKey:] 10 0x6a2648 - [UIRuntimeConnection initWithCoder:] 11 0x7b1a02 UINibDecoderDecodeObjectForValue 12 0x7b1418 UINibDecoderDecodeObjectForValue 13 0x7b10e5 - [UINibDecoder decodeObjectForKey:] 14 0x6a1aa3 - [UINib instantiateWithOwner:options:] 15 0x566e37 - [UIViewController _loadViewFromNibNamed:bundle:] 16 0x567418 - [UIViewController loadView] 17 0x567648 - [UIViewController loadViewIfRequired] 18 0x567882 - [UIViewController视图] 19 0x567b2a - [UIViewController contentScrollView] 20 0x57eef5 - [UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] 21 0x57efdb - [UINavigationController _layoutViewController:] 22 0x57f286 - [UINavigationController _updateScrollViewFromViewController:toViewController:] 23 0x57f381 - [UINavigationController _startTransition:fromViewController:toViewController:] 24 0x57feab - [UINavigationController startDeferredTransitionIfNeeded:] 25 0x5804a3 - [UINavigationController pushViewController:transition:forceImmediate:] 26 0x580098 - [UINavigationController pushViewController:animated:] 27 0x386f - [BVMapViewController parserDidFinishWithStation:] 28 0x785c - [BVParser parseStation:] 29 0xf8a0d5 - [NSThread main] 30 0xf8a034 NSThread _main 31 0x94e53ed9 _pthread_start
我尝试在主线程上执行此操作,但推送的控制器将其视图全部变为黑色。
提前谢谢你,祝你有个美好的一天。
答案 0 :(得分:1)
嗯,正如您在问题中提到的,必须在主线程上推送视图控制器。任何与UIKit的交互都必须在主线程上完成。
至于为什么它显示黑色,这是一个不同的问题,您需要通过标准的故障排除技术解决。一旦它在主线程上并且它正在正确运行,就在显示的类的各种方法(viewDidLoad等)上设置断点,并查看它在哪里绊倒。