2010-09-01 25 views
0

我正在構建一個簡單的基於導航的應用程序使用表。iPhone - 「類」可能不響應「方法」

我有一個自定義「UITableViewCell」來自定義下面附加的表格單元格數據。

@interface NewsCell : UITableViewCell 
{ 
    IBOutlet UILabel *newsTitle; 
} 
- (void)setNewsLabel:(NSString *)title; 
@end 

然後在我的RootViewController的,我在「的cellForRowAtIndexPath」方法設置標籤「newsTitle」的文字如下。

static NSString *MyIdentifier = @"MyIdentifier"; 
MyIdentifier = @"NewsCell"; 

NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if(cell == nil) 
{ 
    [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:self options:nil]; 
    cell = newsCell; 
} 

[cell setNewsLabel:@"hello testing"]; 
return cell; 

當我運行此,應用程序運行正常,但我得到「NewsCell可能不迴應‘-setNewsLabel:’」的警告。

請幫忙!謝謝。

+0

xib中的標識符字符串與「MyIdentifier」相同嗎? – AechoLiu 2010-09-01 13:42:28

+0

是........還是不行。 – ericbae 2010-09-01 13:51:03

回答

0

哪裏變newsCell從何而來?是否真的是NewsCell

+0

是的!但仍然不好。 – ericbae 2010-09-01 13:27:08

+0

...已清理,但仍然收到此警告。很奇怪。 – ericbae 2010-09-01 13:39:46

+0

請參閱我編輯的答案。 – tobiasbayer 2010-09-01 13:41:00

0

您正在創建筆尖,但未將其分配給任何內容。請參閱this question以創建它。

+0

我嘗試了其中一個建議的答案,但無濟於事。這東西正在驅動我香蕉! – ericbae 2010-09-01 13:54:45

+0

問題,你是否按照這個教程:http://blancer.com/tutorials/i-phone/25543/iphone-programming-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/? ? – MishieMoo 2010-09-01 14:19:25

1

RootViewController.m,則需要`#進口 「NewsCell.h」。

或者,在項目的PCH(預編譯頭文件)文件中粘貼#import "NewsCell.h"

底層的問題是,編譯器只知道解析頭文件(或PCH中的頭文件)時以前看到過的方法。

相關問題