1

IMPORTANT EDIT: I posted the wrong error code, like an idiot. I was posting the error for an attempt I had previously made to fix the issue, instead of the first error. Disregard my dumbness, please.

I'm creating a Facebook Feed app in Xcode, and I'm running into trouble in the creation of custom cells for a table. I'm trying to assign values to two UILabels on the custom cell, and it's giving me the error "No visible @interface for 'JSONFeedItemCell' declares the selector 'nameLabel'". My code is as follows:

Master View Controller

- (void)viewDidLoad
{
    UINib *nib = [UINib nibWithNibName:@"JSONFeedItemCell" bundle:nil];
    [[self tableView] registerNib:nib forCellReuseIdentifier:@"JSONFeedItemCell"];
    ... // other stuff, not relevant
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JSONFeedItemCell *cell = [tableView dequeueReusableCellWithIdentifier:
                              @"JSONFeedItemCell"];

    NSDictionary *p = [[[JSONFeedItemStore sharedStore] allItems] 
                              objectAtIndex:[indexPath row]];
    [[cell nameLabel] setText:@"The Name"];
    return cell;
}

Cell Class

#import <Foundation/Foundation.h>

@interface JSONFeedItemCell : UITableViewCell
{

}

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@end

Let me know if you need any additional information or code, I'd be happy to provide it.

Chance
  • 33
  • 1
  • 8
  • Where are you setting the value of nameLabel in your code, as I can't see it here. Also does it work when you set the value of detailLabel? Check also that you've hooked you IB connections correctly – AppHandwerker Aug 02 '12 at 14:51
  • 1
    You _might_ have to typecast the cell to a JSONFeedItemCell when you dequeue it from the tableView. – Wolfgang Schreurs Aug 02 '12 at 15:10
  • Crud, I included the detailLabel line instead of the nameLabel line! Thank you for pointing that out, I'll change it. And I should have my connections to the XIB set properly, though I don't see how that would change anything, as my error is in the compiler, which shouldn't be affected by the XIB, as far as I know. – Chance Aug 02 '12 at 15:13
  • Wolfgang, if you would be kind enough to explain how to do that in a full answer, I'd be happy to accept it if it works. – Chance Aug 02 '12 at 15:15
  • 1
    Are you getting any other compiler warnings? Because, apart from redeclaring imageView, which already exists in UITableViewCell, I can't see anything wrong with this. – jrturton Aug 02 '12 at 15:23
  • The only thing I'm getting is the "Property 'nameLabel' not found..." error. I don't have any other errors or warnings. – Chance Aug 02 '12 at 15:25
  • You did `@synthesize` these properties, right? – Rok Jarc Aug 02 '12 at 15:43
  • Related : http://stackoverflow.com/questions/10727677/no-visible-interface-for-blahdatacontroller-declares-the-selector-amethod – jrturton Aug 03 '12 at 06:11
  • Thank you so much, @jrturhton! That was exactly what was happening! I've been doing research on Tables and Cells for days trying to figure out what was wrong. Thanks again! – Chance Aug 03 '12 at 14:50

2 Answers2

0

Two things: you have to make sure.

#import "JSONFeedItemCell.h"  //in your mainViewController.h

And, as Wolfgang Schreurs suggested, typecast the cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JSONFeedItemCell *cell = (JSONFeedItemCell *)[tableView dequeueReusableCellWithIdentifier:
                              @"JSONFeedItemCell"];

    NSDictionary *p = [[[JSONFeedItemStore sharedStore] allItems] 
                              objectAtIndex:[indexPath row]];
    [[cell nameLabel] setText:@"The Name"];
    return cell;
}

EDIT: since you don't use custom setters/getters you have to synthesize the properties in JSONFeedItemCell.m

@synthesize imageView;
@synthesize detailLabel;
@synthesize nameLabel;

Compiler should warn you if you forgot to do that but with all the possible compiler settings you never know.

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • I modified my code to reflect what you posted, and I'm still getting the same error. – Chance Aug 02 '12 at 15:36
  • I don't think the typecasting is necessary- the error already knows what type of object it is complaining about. – jrturton Aug 02 '12 at 15:37
  • You're right - it is just a _make sure_ precaution. Two more things come to mind: cleaning the project and restarting the xcode (i recall having similiar problem in the past); And checking other .h files in project: you might find a stray line that is confusing the compiler; oh, did you make sure you're importing .h and not .m file (xcode offers both) – Rok Jarc Aug 02 '12 at 15:40
  • I completely closed XCode, and cleaned the project, and it's still giving me the same error. I also double-checked that my imports were correct (and they are). I don't know what sort of stray lines could be causing this, but I'll double check the .h files related to this to be sure. – Chance Aug 02 '12 at 15:54
  • You're code seems correct - that's why xcode was the main suspect :) – Rok Jarc Aug 02 '12 at 15:58
  • In regards to your edit: The properties are synthesized. They were automatically synthesized when I connected the properties to the items on the XIB, if I remember correctly. – Chance Aug 02 '12 at 16:12
  • Sorry i couldn't be of more help - ran out of ideas of what else could be wrong. Best of luck! – Rok Jarc Aug 02 '12 at 16:14
-1

Do you maybe have something like a , I call it, circle import? Xcode gets messed up when you have 2 classes which imports each other. Xcode displays sometimes 'random' errors like this. And sometimes helps to clean and organize project, and restart pc. I have actually no idea why, but it helps sometimes.

  • JSONFeedItemCell only imports foundation, so there's no way for it to be "circle importing". And I restarted the mac, and cleaned and re-built the project, and it's still not working. – Chance Aug 02 '12 at 20:06