0

大家好,

我试图用标签栏控制器和导航控制器制作一个应用程序。但是我遇到了一些问题......当我尝试在我的第二个视图上 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;
}

多谢你们!

4

1 回答 1

-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];
于 2011-09-22T14:38:27.583 回答