Have an error message on some properties. The error messages are commented out in the following code. Don’t understand why I get this error message even though the properties are declared and synthesized in other files?
PlayersViewController.m
#import "PlayersViewController.h"
#import "Player.h"
#import "PlayerCell.h"
@implementation PlayersViewController
@synthesize players;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [self.players count];
}
- (UIImage *)imageForRating:(int)rating
{
switch (rating) {
case 1:return [UIImage imageNamed:@"1StarSmall.png"];
case 2:return [UIImage imageNamed:@"2StarsSmall.png"];
case 3:return [UIImage imageNamed:@"3StarsSmall.png"];
case 4:return [UIImage imageNamed:@"4StarsSmall.png"];
case 5:return [UIImage imageNamed:@"5StarsSmall.png"];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"];
Player *player = [self.players objectAtIndex:indexPath.row];
cell.nameLabel.text = player.name; /*property 'nameLabel' not found on object of tupe "UITableViewCell" */
cell.gameLabel.text = player.game; /*property 'gameLabel' not found on object of tupe "UITableViewCell" */
cell.ratingImageView.image = [self imageForRating:player.rating]; /*property 'ratingImageView' not found on object of tupe "UITableViewCell" */
return cell;
}
The properties are declared and implemented in the following two files:
PlayerCell.h
#import <Foundation/Foundation.h>
@interface Player : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *game;
@property (nonatomic, assign) int rating;
@end
PlayerCell.m
#import "Player.h"
@implementation Player
@synthesize name;
@synthesize game;
@synthesize rating;
@end
UITableViewCell does not have a property called nameLabel, gameLabel or ratingImageView. If you are using your own custom UITableViewCell subclass then you need to tell the compiler that you’re sending messages to an instance of a
PlayerCelland not UITableViewCell.do it like this
PlayerCell *cell = (PlayerCell *) [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"];Alternatively, you can use
idand the compiler won’t have a problem if you don’t use dot notation but I’d use the explicit class version for clarity.As an aside – if that’s your actual code then you’re not instantiating your UITableViewCells which could also prove problematic.