我有一个 UIViewController
类(假设它是 XXX)。我通过代码以模态方式呈现此 View Controller ..
XXX *xxx = [ [XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
我想在 XXX View 的顶部添加一个导航栏。所以我在XXX的loadView
方法中使用了UINavigationBar
对象。
UINavigationBar *navBar = [ [UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:navBar];
[navBar release];
但是,它会抛出错误“EXC_BAD_ACCESS”。有什么帮助...?
谢谢
最佳答案
选项 1:
尝试从名为 XXX 的 viewController 的 XIB 添加导航栏。
选项 2:
添加一个 UINavigationController 并以模态方式呈现它。
替换你的代码:
XXX *xxx = [[XXX alloc] init];
[self presentModalViewController:xxx animated:YES];
[xxx release];
使用此代码:
XXX *xxx = [[XXX alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:xxx];
[self presentModalViewController:navigation animated:YES];
[navigation release];
希望对你有帮助。
关于iphone - 如何在 UIViewController 中添加 UINavigationBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9718445/