【问题标题】:nsObject for using ASIHTTPRequestsnsObject 用于使用 ASIHTTPRequests
【发布时间】:2011-08-30 20:40:07
【问题描述】:

我想创建一个 nsobject,其中包含我的所有方法,这些方法将用于与我的 php 脚本对话并从我的数据库中获取数据。

我想使用 ASIHTTPRequest 包装器为我执行此操作,但是我不确定如何构造此 nsobject,因为将有多种方法调用不同的 php 脚本(或其中具有不同功能的相同 php)。

当我想从视图中调用 nsobject 方法时,我有点迷失,因为我不知道如何使用 - (void) 将数据传递到视图中,我想在该视图中显示数据库中的数据requestFinished:(ASIHTTPRequest *)request{ 方法。

例如nsobject会是这样的

//...
-(IBAction) method1
{
     NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     [request setDelegate:self];
     [request startAsynchronous];
}

-(IBAction) method2
{
     NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     [request setDelegate:self];
     [request startAsynchronous];
}
-(IBAction) method3
{
     NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     [request setDelegate:self];
     [request startAsynchronous];
}

//Then catch each method request with one

- (void)requestFinished:(ASIHTTPRequest *)request{ //etc

//and use one failed request 

- (void)requestFailed:(ASIHTTPRequest *)request{ //etc

还是将 requestFinished 方法放在要显示信息的视图中?

【问题讨论】:

    标签: iphone ios asihttprequest


    【解决方案1】:

    您可能应该将 HTTP 请求回调(requestFinished: 和 requestFailed:) 放在 UIViewController 的子类中。最有可能的是,无论视图控制器控制相关视图,除非强烈需要在视图控制器之间共享功能,在这种情况下,您可以将其分解为一个单例,其唯一工作是处理这些网络请求。无论哪种方式,需要这些数据的视图都应该由它们的视图控制器修改。视图本身不应与网络代码有任何联系。

    【讨论】:

    • 是的,这绝对是有道理的。我在 uitableviews 方面的经验有限,我正在变得越来越好,它只是何时何地传递数据等等,这让我有点不知所措。
    猜你喜欢
    • 2015-11-20
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多