开发者

NSNotification to be called like in a For loop

开发者 https://www.devze.com 2023-03-08 17:52 出处:网络
I have a parser class and a view controller class. In the parser class i am sending a request and receiving an asynchronous response. I want to download the same several times but while sending differ

I have a parser class and a view controller class. In the parser class i am sending a request and receiving an asynchronous response. I want to download the same several times but while sending different parameters each time. I have registered an observer in the class:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataDownloadComplete:) name:OP_DataComplete object:nil];

and then post a notification in :

-(void)connectionDidFinishLoading:(NSURLConnection *)

connection method of the parser class.

 [[NSNotificationCenter defaultCenter] postNotificationName:OP_DataComplete object:nil];

I ca开发者_Python百科n't enclose the observer inside a For loop. What better alternative is there? Please help. Thanks in advance.


You probably do not need a for loop at all. As you said you send a request asynchroniously, so just send it in your observer code instead of making a for loop. Then you get back to your observer after response is downloaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号