Hello guys,
I trying to make a app with tabbar controller and navigation controller. But i get some problems... When i try to popViewController on my second view, the app crash. Some one knows what's going on?
My Delegate:
// -- 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;
}
My First View:
// -- 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];
}
When i push my second view, i try to go back into the navigation. But the app crash...
Error appointed:
// -- main.m
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Thanks guys!
try this:
change:
CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];
to:
CreatePlayersViewController *createPlayer = [CreatePlayersViewController alloc];
also if there are any init methods to call than it should look like this
CreatePlayersViewController *createPlayer = [[CreatePlayersViewController alloc]init];
try somthing like this:
ADD THIS TO THE .h FILE: CreatePlayersViewController *createPlayer
then replace your code above with this:
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];