0

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 "NewsCell may not respond to '-setNewsLabel:'" warning.

Please help! Thank you.

ericbae
  • 9,604
  • 25
  • 75
  • 108

3 Answers3

1

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).

bbum
  • 162,346
  • 23
  • 271
  • 359
0

Where does the variable newsCell come from? Is it really of type NewsCell?

tobiasbayer
  • 10,269
  • 4
  • 46
  • 64
0

You're creating the nib, but not assigning it to anything. See this question to create it right.

Community
  • 1
  • 1
MishieMoo
  • 6,620
  • 2
  • 25
  • 35
  • I tried one of the suggested answers, but to no avail. This thing is driving me bananas! – ericbae Sep 01 '10 at 13:54
  • Question, were you following this tutorial: http://blancer.com/tutorials/i-phone/25543/iphone-programming-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/ ?? – MishieMoo Sep 01 '10 at 14:19