开发者

iPhone SDK: Why is didSelectRowAtIndexPath not being fired?

开发者 https://www.devze.com 2023-01-02 06:07 出处:网络
I have a view with a table on it. When the app starts, it loads the first 5 visble cells. That works as expected.

I have a view with a table on it. When the app starts, it loads the first 5 visble cells. That works as expected.

My problem is that, when I try to scroll down in the table the app crashes with this error.

What I've found is that didSelectRowAtIndexPath is not being called. AFAIK, all I need to do is to subscribe to the delegate. But I must be missing something?

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

Any help appreciated.

2010-06-06 12:25:42.547 iphoneos[18238:207] * -[NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x451a980 2010-06-06 12:25:42.549 iphoneos[18238:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x451a980'

Here is my code to load cells.

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;


So, if this is your interface declaration:

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

And you are getting an exception thrown from this line of code:

-[NSCFString tableView:cellForRowAtIndexPath:]

The fact of the matter is that your tableView's dataSource property is set to a string object. You can't send a cellForRowAtIndexPath message to a string object. My first question is, what is a TableSectionHeaderViewController? That's what your object inherits from, but that's not something I'm familiar with. Generally, I would suggest providing more code in the future.

In any case, the bottom line is that your tableView's dataSource property is set to a string object. Look into where that is set and exactly what object it is being set to. If you provide more code I can help more, but I think you can take it from here. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号