UITableView работает только с одним контроллером - PullRequest
0 голосов
/ 16 января 2011

Итак, у меня есть свой UITableView, с 2 разделами и 1 ячейкой в ​​каждом, и если я нажимаю первый, он работает, а затем второй, он переходит к первому контроллеру.RootViewController - это NavigationController, пытающийся передать ViewControllers.

Вот код для 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];
}

У меня также возникают проблемы с добавлением большего количества разделов и строк / ячеек в разделы.

Спасибо.

Ответы [ 2 ]

1 голос
/ 16 января 2011

Я полагаю, что вы должны сделать переключение в "didSelectRowAtIndexPath" вместо indexPath.section вместо indexPath.row, поскольку оба раздела имеют только одну строку.

1 голос
/ 16 января 2011

У вас есть только одна строка в каждом разделе, поэтому indexPath.row всегда будет нулевым.В didSelectRowAtIndexPath вы должны проверить раздел, а не строку (при условии, что вы намерены сохранить только одну строку на раздел).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...