ReadFile
此代码显示错误......控制可能达到无效功能......我应该返回什么...哪里出错了?
答案 0 :(得分:0)
您需要在其他地方再定义一个条件,例如
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cellWithTextField";
static NSString *cellIdentifier1 = @"cellWithLabel";
static NSString *cellIdentifier2 = @"cell";
if (indexPath.section == 0) {
UserDetailCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:@"cellWithTextField"];
cell.userDetailLabel.text = [userDetail objectAtIndex:indexPath.row];
return cell;
}
else if (indexPath.section == 1) {
DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
cell = [tableView dequeueReusableCellWithIdentifier:@"cellWithLabel"];
cell.userInfoLabel.text = [userInfo objectAtIndex:indexPath.row];
return cell;
}
else if (indexPath.section == 2)
{
NewControllerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.detailLabel.text = [detail objectAtIndex:indexPath.row];
return cell;
} else {
// Some code to return default cell or return nil
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
}
答案 1 :(得分:0)
回到零。 如果你的代码能正常运行"返回nil"将永远不会执行第0部分(零) - 2。
答案 2 :(得分:0)
您只需在功能结束时添加return nil
所以你的代码看起来像这样:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cellWithTextField";
static NSString *cellIdentifier1 = @"cellWithLabel";
static NSString *cellIdentifier2 = @"cell";
if (indexPath.section == 0)
{
UserDetailCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.userDetailLabel.text = [userDetail objectAtIndex:indexPath.row];
return cell;
}
else if (indexPath.section == 1)
{
DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
cell.userInfoLabel.text = [userInfo objectAtIndex:indexPath.row];
return cell;
}
else if (indexPath.section == 2)
{
NewControllerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
cell.detailLabel.text = [detail objectAtIndex:indexPath.row];
return cell;
}
// You can return here default cell or nil
return nil;
}