如果我创建了一个部分,则会发生错误。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 2009-07-06 10:05:29