2010-06-06 88 views
1

我有一張桌子上的視圖。當應用程序啓動時,它會加載前5個可見單元。這按預期工作。iPhone SDK:爲什麼didSelectRowAtIndexPath不被解僱?

我的問題是,當我嘗試在表格中向下滾動時,應用程序崩潰並出現此錯誤。

我發現的是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

所以,如果這是你的接口聲明:

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

你都可以從下面這行代碼拋出一個異常:

-[NSCFString tableView:cellForRowAtIndexPath:] 

事情的事實是,你的tableView的dataSource屬性被設置爲一個字符串對象。您不能將cellForRowAtIndexPath消息發送到字符串對象。我的第一個問題是,什麼是TableSectionHeaderViewController?這就是你的對象繼承的東西,但那不是我熟悉的東西。一般來說,我會建議將來提供更多的代碼。

無論如何,底線是你的tableView的dataSource屬性被設置爲一個字符串對象。查看設置的位置以及設置的對象。如果你提供更多的代碼,我可以提供更多的幫助,但是我認爲你可以從這裏獲得。 :)