iPhone SDK:为什么不会触发didSelectRowAtIndexPath?

时间:2010-06-06 16:27:43

标签: iphone

我有一张桌子就可以了。当应用程序启动时,它会加载前5个可见单元格。这符合预期。

我的问题是,当我尝试在表格中向下滚动时,应用程序会因此错误而崩溃。

我发现没有调用didSelectRowAtIndexPath。 AFAIK,我需要做的就是订阅代表。但我一定错过了什么?

@interface LandingRetailersViewController : TableSectionHeaderViewController<UITableViewDataSource, UITableViewDelegate, UITabBarDelegate> {

任何帮助表示感谢。

  

2010-06-06 12:25:42.547   iphoneos [18238:207] * - [NSCFString   的tableView:的cellForRowAtIndexPath:]:   无法识别的选择器发送到实例   0x451a980 2010-06-06 12:25:42.549   iphoneos [18238:207] * 终止   应用程序由于未捕获的异常   'NSInvalidArgumentException',原因:   '*** - [NSCFString   的tableView:的cellForRowAtIndexPath:]:   无法识别的选择器发送到实例   0x451a980'

这是我加载单元格的代码。

UITableViewCell * cell = nil;
NSInteger index = [indexPath indexAtPosition:1];

NSLog(@"WHAT IS INDEX %i", indexPath);


RoundedGradientTableViewCell *retailerCell = (RoundedGradientTableViewCell *)[tb dequeueReusableCellWithIdentifier:@"RET"];
if(!retailerCell){
    retailerCell = [[[RoundedGradientTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"RET"] autorelease];
}

[retailerCell setArcSize:5.0];
[retailerCell setStrokeSize:1.0];
[retailerCell setStrokeColor:[UIColor clearColor]];
[retailerCell setBackgroundFillColor:[UIColor clearColor]];
[retailerCell setBackgroundColor:[UIColor clearColor]];

Retailer *retailer = [self retailerAtIndex:index];  
if(retailer){
    [[retailerCell textLabel] setText:[retailer name]];
    if([retailer hasImage]){
        [[retailerCell contentImageView] setImage:[retailer image]];
    }
} else {
    [[retailerCell textLabel] setText:@"No title"];
}
cell = retailerCell;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];



NSLog(@"retailer: %@ ", [retailer name]);
NSLog(@"log: %i ", index);

return cell;

1 个答案:

答案 0 :(得分:1)

所以,如果这是你的界面声明:

@interface LandingRetailersViewController : 
TableSectionHeaderViewController <UITableViewDataSource, 
UITableViewDelegate, UITabBarDelegate>

你从这行代码中抛出异常:

-[NSCFString tableView:cellForRowAtIndexPath:]

事实是你的tableView的dataSource属性被设置为一个字符串对象。您无法向字符串对象发送cellForRowAtIndexPath消息。我的第一个问题是,TableSectionHeaderViewController是什么?这就是你的对象继承的东西,但这不是我熟悉的东西。一般来说,我建议将来提供更多代码。

无论如何,底线是你的tableView的dataSource属性被设置为一个字符串对象。查看设置的位置以及确切设置的对象。如果您提供更多代码我可以提供更多帮助,但我认为您可以从这里获取。 :)