2014-01-16 4 views
-1

요청을 보내는 클래스가 많으며 결국 모두 SplitViewController이됩니다. SplitUIviewclass에서는 테이블 뷰에서 데이터를 폴링하고 쓰는 시간이 오래 걸립니다. 긴 폴링은 백그라운드 스레드에서 수행됩니다. 따라서 애플 리케이션 델리게이트에서 변수를 선언했습니다.하지만 그럴 때는 nil입니다. 그리고 문제는 NSMutablearrayappdelegate을 통해 액세스하려고 시도 할 때마다 해당 주소가 nil이고 배열이 출시 될 때입니다. 롱 폴링에 대한 나의 코드는, 나는 또한 출시되고 수신 된 데이터 또는 변수에 내 응용 프로그램 위임 값을 인쇄 할 수 없습니다, 컨트롤을 잃고, 모든 클래스에서 호에서 변수를 유지하는 방법

- (void) longPoll { 

@autoreleasePool 
{ 
//compose the request 
NSError* error = nil; 
NSURLResponse* response = nil; 
NSURL* requestUrl = [NSURL URLWithString:@"http://www.example.com/pollUrl"]; 
NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl]; 

//send the request (will block until a response comes back) 
NSData* responseData = [NSURLConnection sendSynchronousRequest:request 
         returningResponse:&response error:&error]; 

//pass the response on to the handler (can also check for errors here, if you want) 
[self performSelectorOnMainThread:@selector(dataReceived:) 
     withObject:responseData waitUntilDone:YES]; 
} 



//send the next poll request 
[self performSelectorInBackground:@selector(longPoll) withObject: nil]; 
} 

- (void) startPoll { 

[self performSelectorInBackground:@selector(longPoll) withObject: nil]; 
} 

- (void) dataReceived: (NSData*) theData { 
//i write data received here to app delegate table 
} 

나는 데이터에서 내 SplitView 클래스의 다른 메서드를 호출받은 경우

입니다 내가 여기서 다시로드 테이블이나 다른 방법을 호출 할 수 없습니다.

+3

강점/보유로 재산을 설정하십시오 – codercat

+1

"theData"를 dataRecieved : 방법으로 인쇄 할 수 있습니까? 맞습니까? 그렇다면 더 많은 코드를 게시해야합니다. – Ievgenii

+1

dataRecieved에서 theData를 인쇄 할 수 있으며 확실하게 나에게 시간이 충분하지 않은 게시물 d 전체 문제를 제공 할 수 있습니다. – BackStabber

답변

1

캔트 당신이 당신의 ViewControllers에 강한 당신의 속성을 설정/BTW 그래서

property (strong,retain) NSMutableArray *myData;

처럼 유지, 나는 그것이 글로벌 용기의 저장 장소로 AppDelegate에를 사용하는 나쁜 관행 것을 조금 전에 배운 . ApplicationDelegate는 애플리케이션 위임 메소드 및 앱 기초의 초기 설정을위한 장소입니다. navigationController 설정 등.

데이터를 적절한 장소, 핵심 데이터 또는 다른 장소에 저장하는 것이 좋습니다.