1
我需要更新從視圖控制器的進度條讓我們叫他A位於視圖控制器B,更新完成時,我開始從B的NSULRCONNECTION,將訪問方法DidSendBodyData
定義視圖控制器A在該方法中有進度條應該更新,這是我在視圖控制器B的代碼:得到一個參考UIVIEW CONTROLLER
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類中定義的代碼,我需要參考視圖控制器A,其是這裏rootViewController
但上面做的是不正確的,因爲它創建視圖控制器的另一個對象,而不是使用現有的對象,這意味着一個新的進展將創建欄和更新,這不是我想要的,我需要更新視圖控制器A
這是我在視圖控制器A碼的現有:
-(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
(float)totalBytesWritten ,(float)totalBytesExpectedToWrite);
[progress setProgress:((float)(totalBytesWritten))/totalBytesExpectedToWrite];
}
建立連接時在視圖控制器A中調用方法didsendBodyData
,並且應該更新進度條。
如何在不創建新視圖控制器的情況下獲得對視圖控制器A的引用?
在此先感謝您的幫助。