如何解决这些错误的多个视图

时间:2014-08-29 06:52:31

标签: ios iphone ios7

i have multiple table view on a same view how to solve this error

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    if (tableView == method) {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *methodcell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(methodcell == nil){
            methodcell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier];
        }
        methodcell.textLabel.text = [methodarray objectAtIndex:indexPath.row];
        return methodcell;

    }

    else if (tableView == schedule){

        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *schedulecell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if(schedulecell == nil){
            schedulecell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier];
        }
        schedulecell.textLabel.text = [ScheduleArray objectAtIndex:indexPath.row];
        return schedulecell;
    }


}

2 个答案:

答案 0 :(得分:2)

问题是你的函数有的可能性没有返回任何东西。例如,如果您的ifelse if语句都返回FALSE,则您的函数将不会返回任何内容。此功能要求您返回一些内容,因此您有几个选项(完全取决于您想要完成的任务):

  1. 您可以在函数的最后一个括号之前添加return nil;(如果没有执行if分支,则不返回单元格)
  2. 您可以将上次else if更改为else,以便在if返回FALSE
  3. 时执行
  4. 您可以在else声明
  5. 中添加另一个if分支

    总之,您需要在该函数调用结束时返回 某些内容

答案 1 :(得分:1)

如果{},可以在{}之外将单元格转义为外部,如果是{},则根据tableView配置它并返回。

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewStylePlain
                                 reuseIdentifier:CellIdentifier];
}
if (tableView == method) {
   //configure cell for method tableView
} else if (tableView == schedule) {
   //configure cell for schedule tableView
}
return cell;