需要在 NSNotification 回调方法中进行数据库写入
我调用 Web 服务,传递参数,然后在视图控制器类中注册观察者(以通知下载完成):
[self callWebservice:parameter1];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataDownloadComplete:) name:OP_DataComplete object:nil];
然后在我的解析器类中发布通知:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection method of the parser class. [[NSNotificationCenter defaultCenter] postNotificationName:OP_DataComplete object:nil];
在回调方法 dataDownloadComplete 中:我想调用多次使用相同的 Web 服务。
-(void)dataDownloadComplete
{
if([anArray objectAtindex:N]<10)
{
[self callWebservice:parameterN];
NSLog(@"This is getting called everytime (9 times)");
[self writeintoDatabase];
N++;
}
}
但问题是我想将从服务下载的数据写入数据库。奇怪的是,数据库写入发生在“parameter1”调用上,并且继续发生在其他调用上,但没有发生在“parameter9”上(我也需要它)。请注意,日志被调用了 9 次。 writeintoDatabase 代码是完美的。请帮忙。提前致谢。
I make a call to a web service, passing a parameter and then register an observer in a viewcontroller class (to notify completion of download) :
[self callWebservice:parameter1];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataDownloadComplete:) name:OP_DataComplete object:nil];
and then post a notification in my parser class:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection method of the parser class. [[NSNotificationCenter defaultCenter] postNotificationName:OP_DataComplete object:nil];
In the callback method dataDownloadComplete: i would like to call the same web service again several times.
-(void)dataDownloadComplete
{
if([anArray objectAtindex:N]<10)
{
[self callWebservice:parameterN];
NSLog(@"This is getting called everytime (9 times)");
[self writeintoDatabase];
N++;
}
}
But the problem is that i want to write into a database what data i download from the service. The DB writing happens for 'parameter1' call strangely, and goes on for the others but not for parameter9(which i need as well). Note the Log is called all 9 times though. The writeintoDatabase code is perfect. Please help. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论