简体   繁体   English

同步NSURLConnection回调

[英]Synchronous NSURLConnection Callback

I have a nsurlconnection that i set the delegate as self. 我有一个nsurlconnection,我将委托设置为self。 I have the four methods didrecieve, did finish, did fail, and the other one. 我有四种方法,可以接收,完成,失败,以及另一种。 My question is how to set it up so that i include what needs to be done after completion. 我的问题是如何设置它,以便我包括完成后需要做的事情。 This is needed because I have different nsurlconnection requests throughout the class, and have unique responses. 这是必需的,因为我在整个类中都有不同的nsurlconnection请求,并且具有唯一的响应。 Thanks. 谢谢。

Your question is not clear. 您的问题不清楚。 First of all, it doesn't sound like you're using NSURLConnection synchronously, so your question title seems wrong. 首先,听起来好像您不是在同步使用NSURLConnection ,所以您的问题标题似乎不对。 Then, if you want to do something when the connection completes, put it in the did-finish and did-fail methods. 然后,如果您想在连接完成后执行某些操作,请将其放入did-finish和did-fail方法中。

If you want to distinguish among multiple connections, use the parameter for the connection that's passed in to the delegate methods. 如果要在多个连接之间进行区分,请为传入委托方法的连接使用参数。 One thing you can do is have a dictionary whose keys are [NSValue valueWithNonretainedObject:theConnection] . 您可以做的一件事就是拥有一个字典,其键为[NSValue valueWithNonretainedObject:theConnection] The value can be anything of use, including another dictionary. 该值可以是任何有用的值,包括另一个字典。

Or, you can use a separate object to manage and be the delegate for each connection. 或者,您可以使用单独的对象来管理每个连接并成为每个连接的委托。 If there's enough specific to each connection that you have to keep track of data about it, then maybe it warrants a separate object to manage things. 如果每个连接都有足够具体的信息来跟踪有关它的数据,则可能需要一个单独的对象来管理事物。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM