2 つのセクションを持つ動的テーブルを設計したいと考えています。最初のセクションには 4 つのセルがあり、2 つ目のセクションには 41 のセルがあります。これら 2 つのセクションを別々にプログラムしたいのですが、1 つのセクションしか変更できません。各セクションを個別に変更するにはどうすればよいですか。これまでに書いたコードは次のようなものです。
{
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return 4;
else
return 41;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Questions";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Questions"];
cell.textLabel.text = [NSString stringWithFormat:@"Question %lu", (unsigned long)indexPath.row +1];
return cell;
}
}