2011-08-30 8 views
0

내 PHP 스크립트와 대화하고 내 데이터베이스에서 데이터를 가져 오는 데 사용할 모든 메서드가 포함될 nsobject를 만들고 싶습니다.nsObject ASIHTTPRequests를 사용하기 위해

나를 위해이 작업을 수행하는 ASIHTTPRequest 래퍼를 사용하고 싶습니다. 그러나 다른 PHP 스크립트 (또는 다른 함수가있는 동일한 PHP)를 호출하는 여러 메서드가 있으므로이 nsobject를 구조화하는 방법을 잘 모르겠습니다.

어디에서 데이터를 가져올 지 모르겠으므로 뷰에서 nsobject 메서드를 호출하는 것에 대해 생각할 때 abit이 손실됩니다. - (void) requestFinished : (ASIHTTPRequest *) request {method. 예를 들어

는 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 방법을 배치해야합니까?

답변

1

UIViewController의 하위 클래스에 HTTP 요청 콜백 (requestFinished : 및 requestFailed :)을 넣어야합니다. 어떤 뷰 컨트롤러가 관련 뷰를 제어하고 있든간에,보기 컨트롤러간에 기능을 공유해야하는 강력한 요구 사항이 없으면 이러한 네트워크 요청을 처리하는 단독 작업으로 간주 할 수 있습니다. 어느 쪽이든,이 데이터를 필요로하는 뷰는 뷰 컨트롤러에 의해 수정되어야합니다. 뷰 자체는 네트워크 코드와 관련이 없어야합니다.

+0

그래 맞지만 도전적으로 말이됩니다. 나는 uitableviews에 대한 제한된 경험을 가지고 있습니다. 언제 어디서나 데이터를 전달할 수있는 능력이 향상되고 있습니다. –

관련 문제