0

したがって、それぞれに2つのセクションと1つのセルがあるUITableViewがあり、最初のものをクリックすると機能し、2番目のものをクリックすると最初のコントローラーに移動します。RootViewController は、ViewControllers にプッシュしようとしている navigationController です。

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];
}

また、セクションと行/セルをセクションに追加するのにも問題があります。

ありがとう。

4

2 に答える 2

1

各セクションには 1 つの行しかないため、indexPath.row は常にゼロになります。didSelectRowAtIndexPath では、行ではなくセクションをテストする必要があります (セクションごとに 1 つの行のみを保持するつもりであると仮定します)。

于 2011-01-16T09:51:27.810 に答える
1

どちらのセクションにも行が 1 つしかないため、indexPath.row の代わりに「didSelectRowAtIndexPath」で切り替えを行う必要があると思います。

于 2011-01-16T09:52:02.260 に答える