gpt4 book ai didi

ios - UITableViewCell 中的 2 个标签,无需自定义单元格

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:37 26 4
gpt4 key购买 nike

我想在一个单元格中放置两个文本标签。我使用 Json 显示来自服务器的数据,我想显示第一个标题,然后显示下面的文本(不是副标题)。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...

City * cityObject;
cityObject = [ citiesArry objectAtIndex:indexPath.row];
cell.textLabel.text = cityObject.cityState;
cell.textLabel.text = cityObject.cityPopulation;
}

最佳答案

单元格是在 Storyboard还是 NIB 中设计的?如果是这样,您可以将该单元格样式设置为副标题或将两个标签添加到 contentView。为它们分配唯一的标签,以便您可以在 cellForRowAtIndexPath: 方法中查询它们并设置它们的文本。

如果您没有 Storyboard或 NIB 设计单元格,那么像下面这样的东西应该可以工作。

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

static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]
}

// Configure the cell...

City * cityObject;
cityObject = [ citiesArry objectAtIndex:indexPath.row];
cell.textLabel.text = cityObject.cityState;
cell.detailTextLabel.text = cityObject.cityPopulation;
}

关于ios - UITableViewCell 中的 2 个标签,无需自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22057296/

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