2010-10-31 48 views
0

我已經創建了一個UITableViewCell,我試圖將它顯示在我的表格中,但由於某種原因它沒有出現,表格即將變空。當我點擊表格中的單元格時,它將我帶到下一層,這意味着定製的UITableViewCell無法正確渲染。自定義的UITableViewCell不會出現在表中

這裏是我的自定義的UITableViewCell .h文件中

@interface ProductViewCell : UITableViewCell { 
IBOutlet UILabel *titleLabel; 
IBOutlet UILabel *detailLabel; 
IBOutlet UIImageView *imageView; 
} 

@property (nonatomic, retain) UILabel *titleLabel; 
@property (nonatomic, retain) UILabel *detailLabel; 
@property (nonatomic, retain) UIImageView *imageView; 

這裏是.m文件

#import "ProductViewCell.h" 

@implementation ProductViewCell 
@synthesize titleLabel, detailLabel, imageView; 

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

這裏是.h文件,其子類的UITableViewController

@interface ProductCategoryViewController : UITableViewController { 
NSArray *tableDataSource; 

} 

@property (nonatomic, retain) NSArray *tableDataSource; 

這裏ProductCategoryViewController的.m文件

@implementation ProductCategoryViewController 
@synthesize tableDataSource; 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 
      (NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    ProductViewCell *cell = (ProductViewCell*)[tableView 
        dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[ProductViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
        reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row]; 

    cell.titleLabel.text = [dictionary objectForKey:@"name"]; 

    cell.imageView.image = [UIImage imageNamed:[dictionary objectForKey:@"imageUrl"]]; 
    return cell; 
    } 

您的幫助表示讚賞。

感謝, 約傑什

+0

什麼是電池的的.xib文件的名稱? – 2010-10-31 07:38:18

+0

ProductViewCell.xib – Yogesh 2010-10-31 14:59:10

回答

0

我通過做一些改變這方面的工作,在我tableviewcontroller我增加了一個IBOutlet的ProductViewCell和合成相同。

然後,我改變了廈門國際銀行文件ProductViewCell 1)我使文件的所有者我tableViewController 2)然後在這裏我聯繫了,我在tableViewContoller到ProductViewCell創建IBOutlet中。

我不知道這是做正確的方式,但這種ATLEAST現在工作對我來說

相關問題