2011-09-22 141 views
0

好傢伙,問題:的TabBar控制器+導航控制器:編程

我試圖與的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; 
} 

謝謝你們!

回答

-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]; 
+0

不工作......我將創建導航控制器,我的第一個視圖控制器內。 –

+0

您的部分「錯誤指定」可能是「訪問不良」錯誤。這意味着你可以從內存區域寫入或讀取你不想要的內容。不過,仔細查看代碼,看看其他可能出錯的東西 –

+0

檢查我的編輯。你得到一個錯誤,我有一個問題是視圖不會加載。那就是爲什麼隱藏=不存在 –