![](/img/trans.png)
[英]How do I make what my cell looks like update each time there is a change to the object in NSFetchedResultsController that corresponds to the cell?
[英]How do i deal with my response object which corresponds to node ids?
编辑措辞
我正在使用一个名为Drupal-IOS-SDk的第三方库将我的Drupal网站与正在开发的IOS应用程序连接起来。 我使用一种方法来索引我网站上的节点,我只是想知道是否有人对如何处理我的网站的响应有任何了解。 如果我运行与索引方法(getNode方法)类似的代码,可以给出一些上下文,该方法可以正常工作,并且可以如下所示完美访问我的响应:
//code for correctly working nodeGet method
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setValue:@"650" forKey:@"nid"];
[DIOSNode nodeGet:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//print out responseObject
//NSLog(@"%@", responseObject);
//pull data from the responseObject
NSInteger testNumber = [responseObject objectForKey:@"changed"];
NSLog(@"%ld", (long)testNumber);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//we failed, uh-oh lets error log this.
NSLog(@"%@, %@", [error localizedDescription], [operation responseString]);
}];
这是响应对象打印的内容(我没有包括整个内容,但您会明白这一点):
//printed statement for correctly working nodeGet method
{
changed = 1390534644;
comment = 0;
created = 1390534644;
data = "b:0;";
"ds_switch" = "";
"field_additional_pictures" = (
);
"field_author" = {
und =
上面的代码获取节点数据,并在responseObject上调用“ objectforkey”方法使我可以访问数字或其他存储在responseObject中的内容。 在我评论了来自响应对象的提取数据的地方,我得到了整数“ 1390534644”,该整数正确地对应于“更改的”变量,如您从上面的打印响应中所见。 上面的部分工作正常。 这是我感到困惑的下一步:
//code for index method that is in question
NSMutableDictionary *paramsDictionary = [NSMutableDictionary new];
[paramsDictionary setValue:@"books_e_books_other_books" forKey:@"type"];
[DIOSNode nodeIndexWithPage:@"0" fields:@"nid" parameters:paramsDictionary pageSize:@"20"
success:^(AFHTTPRequestOperation *operation, id responseObject) {
//print response object
NSLog(@"%@", responseObject);
NSLog(@"GREAT SUCCESS");
//HERE IS MY PROBLEM!!!
//what do I do with response object?
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//code
NSLog(@"Oh no failed when trying to get the index");
NSLog(@"%@, %@", [error localizedDescription], [operation responseString]);
}];
在本节中,我为所有节点建立索引并从每个节点获取字段,而不是仅从一个节点获取所有信息。 我得到了一个响应,该响应显示出到目前为止一切正常,因为该响应具有正确的信息。 我很困惑,因为我不确定我的响应对象到底是什么。 它是节点的集合,每个节点都有一个“ nid”和“ uri”,如下面的索引方法responseObject所示。 例如,如果我想从下面打印区域的第一个“ nid”中获取值“ 650”,我将如何进行? 我不认为我可以像在第一个工作示例中那样调用“ objectForKey”,因为每个节点都有一个“ nid”。 如果我告诉我的应用查找名为nid的密钥,则它不知道要寻找哪个密钥。 没有唯一键,如何访问数字650? 我在下面打印了索引方法responseObject,因此您可以了解我在说什么。
//printed statement from index method, this is what i am confused about, there are no unique keys how do I access the value 650 or the first nid
{
nid = 650;
uri = "http://www.domain.com/domain_endpoint/node/650";
},
{
nid = 649;
uri = "http://www.domain.com/domain_endpoint/node/649";
},
{
nid = 647;
uri = "http://www.domain.com/domain_endpoint/node/647";
},
您问这个问题已经有几个月了,所以我不确定您是否还在寻找答案,但是万一将来有人需要它。
responseObject是NSDictionary对象的数组。 您可以像数组一样访问responseObject项目,并根据需要的数据来对它们进行任何处理。
例如:
NSArray *responseArray = responseObject;
for (NSDictionary *item in responseArray)
{
// Do something with your item here
// For example:
NSString *uriStr = [item valueForKey:@"uri"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.