我创建了一个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 :(得分:0)
我通过进行一些更改来完成这项工作,在我的tableviewcontroller中,我为ProductViewCell添加了一个IBOutlet并进行了合成。
然后我更改了ProductViewCell的xib文件 1)我将文件的所有者设为我的tableViewController 2)然后我将我在tableViewContoller中创建的IBOutlet链接到ProductViewCell。
我不确定这是否是正确的做法,但至少这对我现在有用