大家好,
我尝试用tabbar控制器和导航控制器制作应用程序。 但是我遇到了一些问题...当我在第二个视图上尝试popViewController时,应用程序崩溃了。 有人知道发生了什么事吗?
我的代表:
// -- PranchetaAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1];
PlayersViewController* playersViewController = [[PlayersViewController alloc] initWithTabBar];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:playersViewController];
[localControllersArray addObject:self.navigationController];
[self.navigationController release];
self.tabBarController.viewControllers = localControllersArray;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
[self.navigationController release];
[localControllersArray release];
return YES;
}
我的第一个视图:
// -- PlayersViewsController.m
- (id)initWithTabBar {
if (self)
{
self.title = @"Players";
self.tabBarItem.image = [UIImage imageNamed:@"PlayersTabBarIcon.png"];
CustomNavigationBarButton *addButtonView = [[CustomNavigationBarButton alloc] initWithImage:@"AddButton.png" withSelected:@"AddButtonSelected.png"];
[addButtonView addTarget:self action:@selector(gotoCreatePlayers) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:addButtonView];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
[addButtonView release];
}
return self;
}
- (void)gotoCreatePlayers {
CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];
[self.navigationController pushViewController:createPlayer animated:YES];
[createPlayer release];
}
当我按下第二个视图时,我会尝试返回导航栏。但应用程序崩溃......
指定错误:
// -- main.m
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
谢谢你们!
答案 0 :(得分:-1)
试试这个:
变化:
CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];
为:
CreatePlayersViewController *createPlayer = [CreatePlayersViewController alloc];
如果有任何init方法要调用,它应该看起来像这个
CreatePlayersViewController *createPlayer = [[CreatePlayersViewController alloc]init];
尝试这样的事情:
添加到.h文件:CreatePlayersViewController *createPlayer
然后用以下代码替换上面的代码:
if (createPlayer ==nil) {
CreatePlayersViewController *nextView = [[CreatePlayersViewController alloc] initWithStyle:UITableViewStylePlain];
self.createPlayer = nextView;
[nextView release];
}
self.meetTheTeam.view.hidden = NO;
[self.navigationController pushViewController:self.meetTheTeam animated:YES];