gpt4 book ai didi

ios - 显示来自 NSMutableString 的特定数据

转载 作者:行者123 更新时间:2023-11-28 20:12:45 25 4
gpt4 key购买 nike

我有包含以下信息的 NSMutableString:

T: Testadata(id:1,title:"Test",subtitle:"test is correct",note:"second test",identifiers:(

这是我的表格实现:

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

static NSString *CellIdentifier = @"TestCell";
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[ [[NSBundle mainBundle] loadNibNamed:@"TestCell" owner:nil options:nil]
lastObject];
}

NSArray *array = [server get_test:10 offset:0 sort_by:0 search_for:@""];
NSMutableString *t = [NSMutableString stringWithFormat:@"%@ ", [array
objectAtIndex:indexPath.row]];


cell.testTitle.text = t;
NSLog(@" T :%@ ", t);

return cell;

}

现在我的 t 中有所有测试数据,我想显示,只是我的行中的标题如何在我的标题标签中只有我的标题而不是整个测试数据?请你帮助我实现这个?

最佳答案

字符串是调用对象的description方法的结果

[array objectAtIndex:indexPath.row]

这是服务器返回的对象之一,那似乎是一个对象服务器 API 返回的特殊类。

我不知道你是什么服务器APIusing, get_test: 方法返回什么样的对象,但通常有是获取从服务器检索到的对象的属性的访问器方法。

首先将对象转换为字符串(使用stringWithFormat:)然后尝试从 string 中提取单个属性既麻烦又容易出错。如果可能,您应该改用正确的访问器方法。

编辑:您现在已经告知您使用 Thrift API。我没有经验使用该 API,但快速查看文档似乎是服务器调用返回模型类 Testadata 的对象数组。因此类似这样的事情应该是可能的:

Testadata *td = [array objectAtIndex:indexPath.row];
cell.testTitle.text = td.title;
cell.testSubtitle.text = td.subtitle;

另一点:获取 cellForRowAtIndexPath 中的对象效率很低,因为该方法被频繁调用。最好只获取一次对象(例如在 viewDidLoad 中)。

关于ios - 显示来自 NSMutableString 的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19501116/

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