【发布时间】:2010-10-31 07:08:04
【问题描述】:
我创建了一个 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
这是 UITableViewController 子类的 .h 文件
@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;
}
感谢您的帮助。
谢谢, 尤格什
【问题讨论】:
-
单元格的 .xib 文件的名称是什么?
标签: ios uitableview