2014-02-24 2 views
1

보기 컨트롤러에서 진행률 표시 줄을 업데이트해야합니다. 뷰 컨트롤러 B에있는 A를 호출 할 수 있습니다. B에서 NSULRCONNECTION을 시작하면 업데이트가 수행되며, DidSendBodyData에 정의 된 메서드에 액세스합니다. 뷰 컨트롤러 A가이 방법으로 업데이트해야합니다 진행 표시 줄이 여기에 뷰 컨트롤러 B에서 내 코드는 다음과 같습니다UIVIEW 컨트롤러에 대한 참조 얻기

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 
UINavigationController * myStoryboardInitialViewController = [storyboard instantiateInitialViewController]; 

HomeViewController *rootViewController = [myStoryboardInitialViewController.viewControllers objectAtIndex:0]; 

NSURLConnection * connection = [[NSURLConnection alloc] 
           initWithRequest:request 
           delegate:rootViewController startImmediately:NO]; 

이이 클래스 B에 정의 된 코드, I는 컨트롤러 A를 볼 참조가 필요 여기 rootViewController 하지만 위의 작업은보기 컨트롤러의 다른 객체를 생성하고 기존의 객체를 사용하지 않기 때문에 올바르지 않습니다. 연결이 설정

-(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{ 
(float)totalBytesWritten ,(float)totalBytesExpectedToWrite); 
[progress setProgress:((float)(totalBytesWritten))/totalBytesExpectedToWrite]; 
} 

때 줄이 만들어 업데이트하고 내가 원하는 것이 아니다 될 것이다, 나는

여기

뷰 컨트롤러 A의 내 코드는 뷰 컨트롤러의 기존 하나를 업데이트해야 뷰 컨트롤러 A에서 메서드 didsendBodyData이 호출되고 진행률 막대가 업데이트되어야합니다.

새보기 컨트롤러를 만들지 않고보기 컨트롤러 A에 대한 참조를 얻으려면 어떻게해야합니까?!

미리 도움을 청하십시오.

답변

0

다른 클래스에 대한 참조를 원하지 않습니다. 위임 진행 상황 업데이트 작업을 원합니다.

protocol을 만들고 첫 번째 컨트롤러에서 구현하십시오. a) 대표자가 있고 b) 대리인이 진행 상황 업데이트에 응답하고 황금색임을 확인하십시오.

관련 문제