从另一个类调用Web服务时出现问题

发布于 2024-10-31 06:42:52 字数 595 浏览 0 评论 0原文

这是我的类,

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

马蹄踏│碎落叶 2024-11-07 06:42:52

(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

寒江雪… 2024-11-07 06:42:52

为视图控制器创建一个要遵循的协议,以便在检索数据时进行回调。视图控制器实现将根据需要刷新显示。

编辑:

创建协议:

@protocol WebServiceDelegate <NSObject>
@optional
- (void) serviceSuccessful: (BOOL)success withData:(NSMutableData*)data;

使用该协议的委托对象创建一个类。还要在此类中创建一个方法,您的 viewController 将调用该方法来开始设置连接:

@interface WebServiceHandler : NSObject {

id <WebServiceDelegate> delegate;}

在 WebServiceHandler 类中编写所有连接委托方法实现。在connectionDidFinishLoading中,设置委托对象:

[[self delegate] serviceSuccessful:YES withData:webData];

使你的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:

@protocol WebServiceDelegate <NSObject>
@optional
- (void) serviceSuccessful: (BOOL)success withData:(NSMutableData*)data;

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:

@interface WebServiceHandler : NSObject {

id <WebServiceDelegate> delegate;}

Write all the connection delegate method implementation in WebServiceHandler class. In connectionDidFinishLoading, set the delegate object:

[[self delegate] serviceSuccessful:YES withData:webData];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文