2012-07-13 88 views
1

首先這裏的頂部是表示含有的UITableView的UIViewController的代碼:製作自定義的UITableViewCell在一個UITableView上的cocos2d層

//View Controller with navigation bar 
InAppPurchaseViewController *purchaseViewController = [[InAppPurchaseViewController alloc] init]; 
purchaseViewController.title = @"Liste de packs"; 
purchaseViewController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissViewController:)] autorelease]; 

//Creation de la navigation bar et release du viewcontroller 
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:purchaseViewController] autorelease]; 
[purchaseViewController release]; 

container = [[UIViewController alloc] init]; 
[container setView:[[CCDirector sharedDirector] openGLView]]; 
[container setModalTransitionStyle: UIModalTransitionStyleCoverVertical]; 
[container presentModalViewController: navController animated: YES]; 

這裏是我的UITableViewCell:

InAppPurchaseCell.h

@interface InAppPurchaseCell : UITableViewCell 
@property (strong, nonatomic) IBOutlet UIImageView *ImageThumbnail; 
@property (strong, nonatomic) IBOutlet UIButton *BuyButton; 
@property (strong, nonatomic) IBOutlet UILabel *TitleLabel; 
@property (strong, nonatomic) IBOutlet UILabel *PriceLabel; 
@end 

InAppPurchaseCell.m

@implementation InAppPurchaseCell 
@synthesize PriceLabel; 
@synthesize TitleLabel; 
@synthesize BuyButton; 
@synthesize ImageThumbnail; 

-(id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
    { 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 
} 
@end 

InAppPurchaseCell.xib

所有IBOutlet中是否正確鏈接

和:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *cellIdentifierCasual = @"ShopCell"; 
    InAppPurchaseCell *cell = (InAppPurchaseCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifierCasual]; 
    if (cell == nil) 
    { 
     cell = (InAppPurchaseCell*)[[[NSBundle mainBundle] loadNibNamed:@"InAppPurchaseCell" owner:nil options:nil]lastObject]; 
     cell.selectionStyle = UITableViewCellSelectionStyleGray; 
    } 
    else 
    { 
     cell.selectionStyle = UITableViewCellSelectionStyleGray; 
    } 
    Packages *packages = [PackagesParser loadData]; 
    Package *package = [packages.Packages objectAtIndex:indexPath.row]; 

    cell.ImageThumbnail.image = [UIImage imageNamed:@"Icon-Small.png"]; 
    cell.PriceLabel.text = @"0,75$"; 
    cell.TitleLabel.text = package.Name; 

    return cell; 
} 

什麼hapenning當表彈出:

2012-07-13 13:56:55.378 Testing[1276:1c103] *** Terminating app due to uncaught 
exception 'NSUnknownKeyException', reason: '[<NSObject 0xa10da00> 
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ImageThumbnail.' 

在這一行:

cell = (InAppPurchaseCell*)[[[NSBundle mainBundle] loadNibNamed:@"InAppPurchaseCell" owner:nil options:nil]lastObject]; 

有人有想法嗎?

回答

1

這可能會幫助你

InAppPurchaseCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell==nil) {  
    cell=[[InAppPurchaseCell alloc]initWithFrame:CGRectMake(0, 0, 200, 100)  
    reuseIdentifier:@"ShopCell"]; 
} 
+0

initWithFrame:方法reuseIdentifier:不贊成我的看法,但我會嘗試此方法...好吧,我不記得了,但我已經嘗試過initWithFrame:方法使用這種方法我不t得到錯誤的表創建,與正確的行數量,但行是空的: cell.PriceLabel.text是沒有權利後cell.PriceLabel.text = @「0,75 $」;這是不正常的=( – 2012-07-13 13:13:42

+1

在inAppCell.h中添加您的標籤價格標籤lable編程在 - (id)initWithFrame:(CGRect)frame reuseIdentifier :(NSString *)aReuseIdentifier { self = [super initWithFrame:frame reuseIdentifier:aReuseIdentifier] ;如果 (個體) {self.priceLabel = [[ALLOC的UILabel] initWithFrame:方法CGRectMake(25,115,220,21)]; self.contentview addsubview:self.priceLabel }嘗試這樣 – Ram 2012-07-13 13:26:20

+0

那麼它的作品標籤,但:不是按鈕,這個解決方案並沒有真正乾淨>< – 2012-07-13 13:44:01

相關問題