尝试使用自定义单元格制作表格视图。我看了一些教程,但没有打开一个新项目,而是一步一步地跟着。我试着用我现在的来做。这样我就可以解决问题并了解更多信息。
所以这里是我到目前为止所做的步骤:简单的表格视图:
(锻炼列表.xib)
WorkoutList.h(workoutTableView 是你在上图中看到的那个)
锻炼列表.m:
- (void)viewDidLoad
{
[super viewDidLoad];
self.workoutTableView.dataSource = self;
self.workoutTableView.delegate = self;
TitleArray = [[NSArray alloc] initWithObjects:@"First", @"Second", @"Third", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return TitleArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
WorkoutCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[WorkoutCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.workoutTitle.text = [TitleArray objectAtIndex:indexPath.row];
cell.workoutImage.image = [UIImage imageNamed:@"list-item-icon3"];
return cell;
}
WorkoutCell.xib:
自定义类是:WorkoutCell 标识符是:Cell
锻炼细胞.h:
我所看到的只是一个空的 TableView ..
我知道这是一个很长的问题,但理解它并找出我的错误在哪里对我来说真的很重要。非常感谢 !