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

时间:2013-12-19 19:16:20

标签: ios objective-c

我在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];


}

1 个答案:

答案 0 :(得分: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;