ObjectiveC - 加载tableView单元格时崩溃

时间:2011-06-16 08:06:35

标签: objective-c ios uitableview

我已经在objectiveC中编写了这个方法(对于iOS,但这并不重要)。调用此方法时,我的应用程序崩溃了。我在.m文件中写了这一切。我无法弄清楚坠机的原因......

-(UITableViewCell *)myCell:(UITableViewCell *)cell 
               forRowIndex:(NSIndexPath *)indexPath
{
    //customize the cell.
    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellId = @"Cell";
    UITableViewCell *cell   = [tableView dequeueReusableCellWithIdentifier:CellId];
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ResultsOne" owner:self options:nil];
        cell         = self.resultsOne;
    }
    cell = [self myCell:cell:indexPath]; //code crashes here
    return cell;
}

我做错了什么?

4 个答案:

答案 0 :(得分:3)

你需要像这样编写方法调用:

cell = [self myCell:cell forRowIndex:indexPath];

答案 1 :(得分:0)

请检查方法“myCell:”的签名。 正如@Robert Fratto指出的那样,可能还有其他一些东西 文件说:
[myRectangle setOrigin:30.0 :50.0]; // This is a bad example of multiple arguments
Since the colons are part of the method name, the method is named setOrigin::. It has two colons as it takes two arguments. This particular method does not interleave the method name with the arguments and, thus, the second argument is effectively unlabeled and it is difficult to determine the kind or purpose of the method’s arguments.

答案 2 :(得分:0)

因为您在呼叫时缺少方法签名。以下是更正。

你的电话:

cell = [self myCell:cell:indexPath]; //code crashing here...! 

实际通话:

cell = [self myCell:cell forRowIndex:indexPath]; // It'll work for sure as we following the correct method signature from your above code.

答案 3 :(得分:-1)

你需要像这样编写方法调用:

if(cell == nil)   
{
       cell = [[[NSBundle mainBundle] loadNibNamed:@"ResultsOne"owner:self options:nil] objectAtIndex:0];          
}

比之后,你打电话:

cell = [self myCell:cell forRowIndex:indexPath];