gpt4 book ai didi

iphone - 自定义UITableViewCell

转载 作者:行者123 更新时间:2023-12-03 19:37:19 25 4
gpt4 key购买 nike

我如何自定义 UITableviewCell,因为我想在单个单元格中查看标签、日期和图片。

最佳答案

有两个选项(可能更多)。您可以使用 native UITableViewCell 属性将内容添加到单元格,或创建自定义单元格(我的意思是,将您自己的 subview 添加到单元格)。开始尝试第一个,它简单优雅,结果会相当不错。例如尝试以下单元格创建方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// notice the Style. The UITableViewCell has a few very good styles that make your cells look very good with little effort
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
// In my case I get the data from the elements array that has a bunch on dictionaries
NSDictionary *d = [elements objectAtIndex:indexPath.row];

// the textLabel is the main label
cell.textLabel.text = [d objectForKey:@"title"];

// the detailTextLabel is the subtitle
cell.detailTextLabel.text = [d objectForKey:@"date"];

// Set the image on the cell. In this case I load an image from the bundle
cell.imageView.image = [UIImage imageNamed:@"fsaint.png"];

return cell;
}

关于iphone - 自定义UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4744658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com