我想创建更详细的表格单元格。我发现的一个例子是 reddit.com 客户端 AlienBlue。每个单元格都有一张图片,即帖子的标题,然后在其下方还有其他四段文字。如何在表格单元格中“分层”文本?
问问题
89 次
4 回答
6
嗨,您应该将UITableViewCell子类化为表格视图中单元格的自定义用户界面。另请参阅:UITableViewDataSource和UITableViewDelegate以获取有关表格视图的其他选项。
可能您的子类 UiTableViewCell 将具有标题 (UILabel)、标题 (UILabel) 和图像 (UIImageView) 的自定义字段
例子:
于 2013-05-07T03:53:36.943 回答
2
您将需要创建一个自定义UITableViewCell
. 这很简单,可以完全用代码(我最喜欢的)或通过 IB 来完成。
谷歌custom UITableView cell
一些很棒的教程。
于 2013-05-07T03:47:19.570 回答
1
- 使用NSMUtableDictionary的NSMutableArray,而不是 NSArray 或 NSMutableArray,来保存数据(字符串、图像等)。
- 将表格单元格样式属性设置为UITableViewCellStyleSubtitle以便表格可以显示详细的TextLabel(cell.detailTextLabel.text)。
- 您可以为表格单元格设置图像。
例子
- (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;
}
于 2013-05-07T04:00:51.653 回答
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;
}
于 2013-05-07T04:23:20.070 回答