Iphone [indexPath行]中的EXC\u错误访问

Iphone [indexPath行]中的EXC\u错误访问,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我正在自定义表格单元格。我有这段代码(简化),当我试图访问[indexath行] -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"WCFPictureCell"; static NSString *CellNib = @"WCFPictureCell";

我正在自定义表格单元格。我有这段代码(简化),当我试图访问
[indexath行]

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"WCFPictureCell";
    static NSString *CellNib = @"WCFPictureCell";
    WCFPictureCell *cell = (WCFPictureCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
        cell = (WCFPictureCell *)[nib objectAtIndex:0];
    }
    NSLog(@"iph    %@", indexPath);
    NSLog(@"iphrow %@", [indexPath row]);
    return cell;
}
我做错了什么


谢谢
nsindepath
row
方法返回一个
NSInteger

这是一个基本类型,不是对象

因此,您不能使用
%@
打印它

你想要的是:

NSLog( @"iphrow %i", [ indexPath row ] );
您遇到分段错误,因为
%@
用于指向对象的指针。
当您传递一个整数时,NSLog将尝试在该整数值指定的内存地址处打印一个对象。

尝试此代码(重构一点)。您的错误在[indexPath行]上,该行返回int use(%i not%@)


您使用
%i
的原因是什么?我一直使用
%d
表示整数,我知道
NSInteger
只是
int
的一个typedef,但是使用它除了首选项之外还有其他原因吗?
%I
%d
printf
是一样的。两者都用于有符号整数。这只是习惯的问题。但是请注意,
%i
%d
scanf
中有不同的含义。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WCFPictureCell *cell = (WCFPictureCell *)[tableView dequeueReusableCellWithIdentifier:@"WCFPictureCell"];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"WCFPictureCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }
NSLog(@"iph    %@", indexPath);
NSLog(@"iphrow %i", [indexPath row]);
return cell; }