2011-12-21 3 views
0

一部のプロパティでエラーメッセージが表示されます。エラーメッセージは、次のコードでコメントアウトされています。プロパティが宣言され、他のファイルで合成されているにもかかわらず、なぜこのエラーメッセージが表示されるのか分かりませんか?プロパティエラーが表示されない

性質は次の2つのファイルで宣言され、実装されている

#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; 
} 

PlayersViewController.m:

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 

答えて

2

UITableViewCellには、nameLabel、gameLabel、またはratingImageViewというプロパティがありません。独自のカスタムUITableViewCellサブクラスを使用している場合は、UITableViewCellではなくPlayerCellのインスタンスにメッセージを送信していることをコンパイラに伝える必要があります。

はまた、この

PlayerCell *cell = (PlayerCell *) [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"];

のようにそれを行うには、idを使用することができますし、ドット表記を使用しない場合、コンパイラは問題はありませんが、私は明示的なクラスのバージョンを使用したいです明快さ。余談として

id cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"]; 
[cell nameLabel].text = @""; //etc 

- それはあなたの実際のコードだならば、あなたはまた、問題になることができ、あなたのUITableViewCellsをインスタンス化していません。

static NSString *CellIdentifier = @"Cell"; 

PlayerCell *cell = (PlayerCell *)[tableView dequeueReusableCellWithIdentifier:@"PlayerCell"]; 
if (nil == cell){ 
    cel = [[[PlayerCell alloc] yourInitMethodWithCellIdentifier:CellIdentifier] autorelease]; 
} 
Player *player = [self.players objectAtIndex:indexPath.row]; 
cell.nameLabel.text = player.name; 
cell.gameLabel.text = player.game; 
cell.ratingImageView.image = [self imageForRating:player.rating]; 
return cell; 
+0

ありがとうございます。それはうまくいった。再度、感謝します! – pdenlinger

1

あなたはNSObjectある「プレイヤー」のインスタンスを作成し、「PlayerCell.m」と呼ばれるファイルを持っています。代わりに、 "PlayerCell.m"にUITableViewCellのサブクラスである "PlayerCell"のインスタンスを作成する必要があります。彼らは実際には「Player.h」であれば

そこから、PlayerCell等の特性UILabel *nameLabelUILabel *gameLabel

あなたは「PlayerCell.h」と「PlayerCell.m」と呼ばれることになったスニペットを持っている必要があります罰金に見えます代わりに "Player.m"を使用します。

関連する問題