1

我有一个UIViewControllerwithin a UINavigationController,我正在UIViewController从一个 XIB 文件将一秒钟推到导航堆栈上。此 XIB 还包括UINavigationItem用于第二个视图控制器的标题和按钮,但在加载 XIB 时会忽略这些。有任何想法吗?

这是我的代码(photoViewController 是第二个 viewController)

- (void) displayPhotoWithId:(int)photoId {

    if (_photoViewController == nil) {
        self.photoViewController = [[[PhotoViewController alloc] initWithNibName:@"PhotoView" bundle:[NSBundle mainBundle]] autorelease];        
    }

    _photoViewController.photoId = photoId;

    [self.navigationController pushViewController:_photoViewController animated:YES]; 

}
4

2 回答 2

3

You can wire this up from interface builder. Add something like this to your view controller:

IBOutlet UINavigationItem* navigationItem;

Then wire it up to the view controller outlets (from File Owner, presumably, to the UINavigationItem in your XIB). I have done this and it works fine. I suppose UINavigationController looks for the 'navigationItem' automagically.

于 2011-03-21T01:29:52.483 回答
0

导航项被忽略,因为它与这个控制器无关,它只是碰巧在这个控制器的 XIB 中。控制器的导航项是在实例化时创建的。您必须在代码中设置标题和导航按钮(viewDidLoad例如),因为控制器没有navigationItem插座。XIB 中的 UINavigationItem 仅在 UINavigationController 的根控制器内工作。

于 2011-03-09T17:51:19.227 回答