我制作了一个具有标签和 imageView 的自定义单元格,自定义单元格单元格有一个带有标识符 CustomTableCell 的类 customCellClass。这是结果屏幕截图,没有传递任何数据,但自定义表格出现如您所见
这是我从数组 *name 获取数据的 .m 文件。请看看我错过了什么。顺便说一句,我正在尝试 [self.tableView reloadData];在 viewdidload 但我不知道 y,但我无法启动它。
@synthesize name = _name;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.name = [NSArray arrayWithObjects:@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third",@"First", @"Second", @"Third", nil];
// self.name = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.name count];
}
-(void) viewDidAppear:(BOOL)animated{
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CustomTableCell";
customCellClass *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[customCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [self.name objectAtIndex:indexPath.row];
cell.imageThumb.image = [UIImage imageNamed:@"images.jpeg"];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
@end
顺便说一句,这是我使用的自定义表格单元格