views:

134

answers:

2

Hi Guys,

I'm trying to build an app where I have a TabBarController with 4 entries. When I select the first entry, a view with a UITableView shows up. This TableView is filled with several entries.

What I would like to do is: When an entry out of that UITableView gets selected, another view should show up; a detailview.

.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.row == 0) {

if(self.secondView == nil) {
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.secondView = secondViewController;
[secondViewController release];
}

// Setup the animation
[self.navigationController pushViewController:self.secondView animated:YES];

}
}

.h

#import <UIKit/UIKit.h>
#import "SecondViewController.h"


@interface FirstViewController : UIViewController {

SecondViewController *secondView;

NSMutableArray *myData; 
}
@property (nonatomic, retain) SecondViewController *secondView;
@property (nonatomic, copy, readwrite) NSMutableArray* myData;

@end

This is what I have so far.

Unfortunately.. the code runs, bit the second view does not show up.

A: 

What is the value of self.navigationController?

You want your UITabBarController to bring up the navigation view associated with a UINavigationController, which your custom view with a UITableView should be the top view on it's view stack. You then should be able to push your detail view onto the UINavigationController with pushViewController:animated:

UINavigationController reference

matthewc
A: 

Is your first view controller wrapped in a UINavigationController? When you set up your UITabBarController, you should add UINavigationControllers rather than your UIViewController subclasses, e.g.:

FirstViewController *viewControl1 = [[FirstViewController alloc] init];
UINavigationController *navControl1 = [[UINavigationController alloc] initWithRootViewController:viewControl1];
UITabBarController *tabControl = [[UITabBarController alloc] init];
tabControl.viewControllers = [NSArray arrayWithObjects:navControl1, <etc>, nil];
//release everything except tabControl

Also, based on your code, you don't need to keep your secondViewController as an ivar, since UINavigationController automatically retains its view controllers (and retaining it when you're not displaying it will use up unnecessary memory).

eman