![](/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.