从另一个类调用Web服务时出现问题
这是我的类,
#import "newsFeedController.h"
- (void)viewDidLoad {
//statements
webService = [[WebServiceManager alloc] init];
[webService setDelegate:self];
//am calling the webservicemanager class here
[webService userStatusUpdateGet:@"1" endLimit:@"10" setSessionID:[[UserSession getInstance] SESSION_ID]];
//am printing.....
nslog(@"printing result %@",webService.test);
此测试是来自 webServiceManager
类的数组,只有在访问后才必须返回 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
方法
我该怎么做?谢谢
(正在使用 json 请求和响应)
this is my class
#import "newsFeedController.h"
- (void)viewDidLoad {
//statements
webService = [[WebServiceManager alloc] init];
[webService setDelegate:self];
//am calling the webservicemanager class here
[webService userStatusUpdateGet:@"1" endLimit:@"10" setSessionID:[[UserSession getInstance] SESSION_ID]];
//am printing.....
nslog(@"printing result %@",webService.test);
this test is a array from webServiceManager
class that has to return only after going to
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
method
how do I do this?.Thanks
(am using json request and response)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(void)connectionDidFinishLoading:(NSURLConnection *)connection
不是 WebServiceManager 的委托方法吗?如果是,它应该可以在您的类中访问,您可以在其中实现该方法的操作Isn't
(void)connectionDidFinishLoading:(NSURLConnection *)connection
a delegate method of WebServiceManager? If yes it should be accessible within your class where you can implement the method's action为视图控制器创建一个要遵循的协议,以便在检索数据时进行回调。视图控制器实现将根据需要刷新显示。
编辑:
创建协议:
使用该协议的委托对象创建一个类。还要在此类中创建一个方法,您的 viewController 将调用该方法来开始设置连接:
在 WebServiceHandler 类中编写所有连接委托方法实现。在connectionDidFinishLoading中,设置委托对象:
使你的viewController符合WebServiceDelegate协议,并为serviceSuccessful方法提供一个实现。现在,一旦 WebServiceHandler 类完成从连接检索数据,就会在 viewController 中调用此方法。
Create a protocol for your view controllers to conform to, for callbacks when the data is retrieved. The view controller implementation will refresh display as appropriate.
EDIT:
Create a protocol:
Create a class with delegate object of this protocol. Also create a method in this class which would be called by your viewController to start setting up the connection:
Write all the connection delegate method implementation in WebServiceHandler class. In connectionDidFinishLoading, set the delegate object:
Make your viewController conform to WebServiceDelegate protocol and give an implementation to serviceSuccessful method. Now this method would be called in the viewController, as soon as WebServiceHandler class has finished with retreiving data from the connection.