0

我在 AppDelegate 中以编程方式创建了一个 UITabBarController。我还创建了两个 UINavigationController,其中包含一些 UIViewController。我将导航控制器添加到 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 lock。这可能是从辅助线程调用 UIKit 的结果。现在崩溃... 1 0x58a76a9 WebThreadLock 2 0x5bfdfe -[UITextView _updateForNewSize:withOldSize:] 3 0x5c00b4 -[UITextView setFrame:] 4 0x4c59df UIViewCommonInitWithFrame 5 0x4c5bae -[UIView initWithCoder:] 6 0x4d9fb7 -[UITextViewScrollView inCoder:][7]的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:选择:startDeferredTransitionIfNeeded:] 25 0x5804a3 - [UINavigationController的pushViewController:过渡:forceImmediate:] 26 0x580098 - [UINavigationController的pushViewController:动画:] 27 0x386f - [BVMapViewController parserDidFinishWithStation:] 28 0x785c - [BVParser parseStation:] 29 0xf8a0d5 - [NSThread主] 30 0xf8a034 NSThread _main 31 0x94e53ed9 _pthread_start

我试图在主线程上执行此操作,但推送的控制器的视图全黑。

提前谢谢你,祝你有美好的一天。

4

1 回答 1

1

好吧,正如您在问题中提到的那样,您必须将视图控制器推送到主线程上。与 UIKit 的任何交互都必须在主线程上完成。

As to why it shows up black, that is a different issue which you need to resolve by standard troubleshooting techniques. Once it is on the main thread and it is running correctly, set breakpoints on the various methods of the class being displayed (viewDidLoad, etc) and see where it is tripping up.

于 2012-10-21T19:28:36.967 回答