我一直在竭尽全力,试图让一个基本的NavigationController正常工作,让我可以轻松地在视图之间来回切换。我觉得我正在取得进步,但我显然遗漏了一些关键的东西。我现在让我的模板应用程序推送视图,但只需添加指向目标NIB的initWithNibName即可。尝试向这些辅助视图添加任何功能都会导致应用程序崩溃,并显示SIGABRT错误。我无法想象这是对的..。如果我只有一个普通的NIB,那么这个开关就工作得很好。我向secondViewcontroller中添加的惟一内容是一个标签和一个用一些垃圾文本填充标签的按钮。然而,当我按下切换按钮按下这个视图时,我得到了SIGABRT。我希望能够将功能放在不同的视图控制器中。我觉得我已经很接近了,但这太让人恼火了。有谁能指出我哪里错了吗?
#import "mainViewController.h"
@implementation mainViewController
-(void)switchView {
UIViewController *secondViewController = [[UIViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
secondViewController.title = @"My First View";
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
}
-(void)switchViewTwo {
UIViewController *thirdViewController = [[UIViewController alloc] initWithNibName:@"thirdViewController" bundle:nil];
thirdViewController.title = @"My second View";
thirdViewController.view.backgroundColor = [UIColor redColor];
[self.navigationController pushViewController:thirdViewController animated:YES];
[thirdViewController release];
}发布于 2011-07-29 01:40:36
而不是
UIViewController *secondViewController = [[UIViewController alloc] initWithNibName:@"secondViewController" bundle:nil];放在这里:
MySecondViewController *secondViewController = [[MySecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];我的MySecondViewController应该是您的UIViewController的名称,还要检查XIB的名称是否真的叫做secondViewController。最后:
MySecondViewController而不是UIViewController.https://stackoverflow.com/questions/6835357
复制相似问题