iPhone - "Class" may not respond to "method"
I am building a simple Navigation-based app using tables.
I have a custom "UITableViewCell" to customize the table cell data attached below.
@interface NewsCell : UITableViewCell
{
IBOutlet UILabel *newsTitle;
}
- (void)setNewsLabel:(NSString *)title;
@end
And then in my RootViewController, I set the text of the label "newsTitle" in "cellForRowAtIndexPath" method as follows.
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;
When I run this, the app runs fine, but I get "NewsCel开发者_开发技巧l may not respond to '-setNewsLabel:'" warning.
Please help! Thank you.
In RootViewController.m
, you need to `#import "NewsCell.h".
Or, stick #import "NewsCell.h"
in your project's PCH (pre-compiled header) file.
The underlying issue is that the compiler only knows about methods that it has previously seen when parsing the header files (or ones in the PCH).
You're creating the nib, but not assigning it to anything. See this question to create it right.
Where does the variable newsCell
come from? Is it really of type NewsCell
?
精彩评论