开发者

Xcode 4: using NavigationController to create multiple levels of UITableViews

开发者 https://www.devze.com 2023-04-12 01:51 出处:网络
I would like to use the NavigationController to create multiple levels of UITableViews.I start with a RootViewController, as created by Xcode for a new NavigationController project, which displays a t

I would like to use the NavigationController to create multiple levels of UITableViews. I start with a RootViewController, as created by Xcode for a new NavigationController project, which displays a table and I can select a row which pushes onto the Navigation stack to display another table using FirstTable.xib and related files. When I then select a row in that table I again push onto the Navigation stack to display a third table (SecondTable.xib), but at this point only blank cells get displayed. Obviously I am missing something that will make this navigation work properly. Any ideas?

Here is the basic structure I am using for the code at the levels below the RootViewController with the obvious bits left out e.g. cellForRowAtIndexPath method

@interface FirstTable : UITableViewController {
    NSArray     *firstList;
}
@property (nona开发者_开发问答tomic, retain) NSArray *firstList;

@implementation FirstTable
@synthesize firstList;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        self.title = @"First Table View";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    firstList = [[NSMutableArray alloc] initWithObjects:
             @"Clubs & officials",
             @"Grade",
             nil];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewController *secondView = [[UITableViewController alloc] initWithNibName:@"SecondTable" bundle:nil];
     [self.navigationController pushViewController:secondView animated:YES];
     [secondView release];
}


OK, it looks like the answer is to use this code just above pushing the ViewController

UITableViewController *secondView = [[NSClassFromString(@"SecondTable") alloc] initWithNibName:@"SecondTable" bundle:nil];

I guess I wasn't creating an instance of the class from creating the UITableViewController for the second table. But then why does the original version work for the first table, i.e. the one called by rootViewController?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号