views:

48

answers:

3

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.

A: 

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

tob
YES! but still no good.
ebae
... cleaned, but still getting this warning. very strange.
ebae
See my edited answer please.
tob
Hi tob, I declared "newsCell" in the RootViewController.h@interface RootViewController : UITableViewController { IBOutlet NewsCell *newsCell;}
ebae
Did you make sure to connect the IBOutlet in IB?
MishieMoo
A: 

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

MishieMoo
I edited my post after I saw the code. Please see above!
MishieMoo
I tried one of the suggested answers, but to no avail. This thing is driving me bananas!
ebae
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
+1  A: 

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

related questions