好的,我为此尝试了很多不同的方法。我想调用一个 JSON API,获取它的响应,保存键值,然后用不同的参数再次调用它。最近,我尝试在 for 循环中调用 URL 方法,在发布 connectionDidFinishLoading:
通知时在观察者中发布 NSNotification 和 NSLogging 值。但它只是多次记录最终调用的值。
我用它来初始化连接......
eventConnection=[[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] delegate:self startImmediately:NO];
[eventConnection scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[eventConnection start];
这是委托方法...
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSNotification *eventNotification=[NSNotification notificationWithName:@"eventsFound" object:nil userInfo:responseDict];
[[NSNotificationQueue defaultQueue]enqueueNotification:eventNotification postingStyle:NSPostNow coalesceMask:NSNotificationCoalescingOnName forModes:nil];
}
关于我如何实现这一目标的任何建议?