UITableView only pushes to one controller

Posted by Mitochondria on Stack Overflow See other posts from Stack Overflow or by Mitochondria
Published on 2011-01-16T09:38:49Z Indexed on 2011/01/16 9:53 UTC
Read the original article Hit count: 285

So I have my UITableView, with 2 sections and 1 cell in each, and if I click the first one, it works, then the second one, it goes to the first controller. RootViewController is a navigationController, trying to push to ViewControllers.

Here's the code for the tableView:

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0)
        return 1;
    else
        return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if(section == 0){
        return @"Terminal/SSH Guides";
    }else{
        return @"Cydia Tutorials";
    }
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    if(indexPath.section == 0){
        cell.text = @"Changing Password for root";
    } else {
        cell.text = @"Hiding Sections";
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    id newController;
    switch (indexPath.row) {
        case 0:
            newController = [[rootpassword alloc] initWithNibName:@"rootpassword" bundle:nil];
            break;
        case 1:
            newController = [[hidingsections alloc] initWithNibName:@"hidingsections" bundle:nil];
            break;
        default:
            break;
    }
    [self.navigationController pushViewController:newController animated:TRUE];
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
}

I'm also having trouble adding more sections and rows/cells to sections.

Thanks.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c