UITableView
2 つの動的セルでグループ化された情報を表示しようとしています。グループ化された各UITableView
ビューを 10 回呼び出す必要があります。それぞれがグループ化UITableView
され、その 2 つのセル間で異なる情報が表示されます。
現在、データベースに保存されているすべてのデータを表示しようとしていますposts
。ただし、このバージョンを実行すると、アプリがクラッシュします。returnを return[self.posts count]
に変更すると、予測どおり、1 つのセクションのみをロードできます。numberOfSectionsInTableView:
1
私の質問は、それぞれが異なる情報を持つ 10 個のグループ化されたテーブル セクションを表示するにはどうすればよいですか?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return [self.posts count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger returnValue = 2;
switch (section) {
case 0:
{
returnValue = 2;
break;
}
default:
break;
}
return returnValue;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier1 = @"Cell";
UITableViewCell *cell;
if (indexPath.section==0)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
}
if (indexPath.row==0)
{
cell.textLabel.text = [[self.posts objectAtIndex:indexPath.row] objectForKey:@"name"];
}
if (indexPath.row==1)
{
cell.textLabel.text = [[self.posts objectAtIndex:indexPath.row] objectForKey:@"message"];
}
}
return cell;
}