显示来自 NSMutableString 的特定数据 [英] Show specific data from NSMutableString

查看:28
本文介绍了显示来自 NSMutableString 的特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有此信息的 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 中有所有 Testdata,我想显示,只是在我的行中添加标题,我怎么能在我的标题标签中只有我的标题而不是整个 Testdata?你能帮我实现这个吗?

now I have all Testdata in my t , I want to show, just title in my rows how can I just have my title instead of whole Testdata in my title label?would you please help me in this implementation?

推荐答案

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

The string is the result of calling the description method on the object

[array objectAtIndex:indexPath.row]

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

which is one of the objects returned by the server, and that seems to be an object of a special class returned by the server API.

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

I don't know what server API you are using, and what kind of objects are returned by the get_test: method, but usually there are accessor methods to get the properties of the objects retrieved from the server.

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

Converting the object to a string first (using stringWithFormat:) and then trying to extract a single property from the string is cumbersome and error-prone. If possible, you should use the proper accessor methods instead.

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

You have now told that you use the Thrift API. I have no experience with that API, but from a quick look at the documentation is seems that the server call returns an array of objects of the model class Testadata. Therefore something similar to this should be possible:

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

另一个备注: 获取cellForRowAtIndexPath 中的对象非常低效,因为该方法被频繁调用.最好只获取一次对象(例如在 viewDidLoad 中).

Another remark: Fetching the objects in cellForRowAtIndexPath is very inefficient, because that method is called frequently. It is better to fetch the objects only once (for example in viewDidLoad).

这篇关于显示来自 NSMutableString 的特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆