セクションを作成すると、エラーが発生します。UITableviewセクションエラー - objc_msgSend
私は既にセクションインデックスを0と1に設定しようとしましたが、どちらも役に立ちませんでした。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier1 = @"Cell1";
if(indexPath.section == 1) {
if(indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.text = @"test 1";
}
return cell;
}
else if(indexPath.row == 1) {
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil) {
cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
cell1.text = @"test 2";
}
return cell1;
}
}
else if(indexPath.section == 2) {
if(indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.text = @"test 1";
}
return cell;
}
else if(indexPath.row == 1) {
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil) {
cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
cell1.text = @"test 2";
}
return cell1;
}
}
}
セクションは実際には1から始まります。 ' - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView'関数は常に少なくとも '1'ではなく '0'を返します。これはクラッシュの原因にもなります。 – Jake
実際には常に1つのセクションですが、インデックスパスの最初のセクションの番号はゼロですか? indexPath.section == 0 - >最初のセクション – drvdijk
+1 - コンパイラは、(非void)関数を通るパスのどれかが何も返されないという事実についてコンパイラが警告するはずです。 – frankodwyer