【问题标题】:Error: Control reaches end of non-void function [closed]错误:控制到达非无效函数的结尾[关闭]
【发布时间】:2013-12-19 19:16:19
【问题描述】:

我在 tableViewController 类中使用以下代码: 并出现以下错误:

错误:控制到达非空函数的结尾

//customize the appearance of the table view cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    //configure the cell

    cell.textLabel.text = [optionList objectAtIndex:indexPath.row];


}

【问题讨论】:

  • 你试过用谷歌搜索错误信息吗?
  • 是的,我有很多指向该网站的链接,但每当我尝试使用解决方案时,我发现它永远无法正常工作。
  • @user3120442 在方法主体的末尾添加:return cell;
  • 天哪,谢谢 Wain!!!!

标签: ios objective-c


【解决方案1】:

只需将您的方法替换为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    //configure the cell

    cell.textLabel.text = [optionList objectAtIndex:indexPath.row];

    //This code you did not added earlier...
    return cell;

}

我刚刚在您的代码中添加了return cell;

【讨论】:

    猜你喜欢
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    相关资源
    最近更新 更多