2012-07-13 34 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

相关问题