我想创建更详细的表格单元格。我找到的一个例子是reddit.com客户端AlienBlue。每个单元格都有一个图像,帖子的标题,然后是其他四个文本。如何在表格单元格中“分层”文本?
答案 0 :(得分:6)
您好,您应该将UITableViewCell子类化为表格视图中单元格的自定义用户界面。 另请参阅:UITableViewDataSource和UITableViewDelegate了解有关表格视图的其他选项。
你的子类UiTableViewCell可能会有标题(UILabel),标题(UILabel)和图像(UIImageView)的自定义字段
示例:
答案 1 :(得分:2)
您需要创建自定义UITableViewCell
。它非常简单,可以完全用代码(我最喜欢的)或通过IB来完成。
Google custom UITableView cell
提供了一些很棒的教程。
答案 2 :(得分:1)
实施例
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
UIImage *image = [[list1 objectAtIndex:indexPath.row] objectForKey:key1a];
cell.imageView.image = image;
NSString *categoryname = [[list1 objectAtIndex:indexPath.row] objectForKey:key1b];
cell.textLabel.text = categoryname;
cell.detailTextLabel.text = [[list1 objectAtIndex:indexPath.row] objectForKey:key1e];
cell.detailTextLabel.textColor = [UIColor blueColor];
return cell;
}
答案 3 :(得分:0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[NSString stringWithFormat:@"%@",[appdelegate.name objectAtIndex:indexPath.row]];
UIImage *image = [[array1 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [[array1 objectAtIndex:indexPath.row];
return cell;
}