我用一個委託方法強制更新我的視圖後popToRootViewController。我的rootViewController稱爲網絡上傳類,完成後,我想重置rootViewController上的表單字段。
在網絡上傳類,我創建了一個委託協議:
@protocol MyNetworkDelegate <NSObject>
@required
- (void) uploadCompleted;
@end
@interface MyNetworkUploader : NSObject{
id <MyNetworkDelegate> _delegate;
}
@property (nonatomic,strong) id delegate;
//other properties here
+(id)sharedManager;
-(int)writeAssessments;
@end
在MyNetworkUploader.m:
-(int)writeAssessments{
//code here to do the actual upload
//.....
//this is a non-view class so I use a global navigation controller
//maybe not the best form but it works for me and I get the required
//behaviour
[globalNav popToRootViewControllerAnimated:NO];
[[globalNav.view viewWithTag:1] removeFromSuperview];
[_delegate uploadCompleted];
}
然後,在我的RootViewController的:
//my upload is done within a completion block so I know when
//it's finished
typedef void(^myCompletion)(BOOL);
-(void) uploadAssessment:(myCompletion) compblock{
//do the upload
sharedManager=[MyNetwork sharedManager]; //create my instance
sharedManager.delegate=self; //set my rootViewController as the network class delegate
int numWritten= [sharedManager writeAssessments];
compblock(YES);
}
#pragma mark - protocol delegate
-(void)uploadCompleted{
//this is a local method that clears the form
[self clearTapped:nil];
}
我不建議這是最好的解決方案,但它對我來說是一種享受!
您是否將各種類型的視圖控制器嵌套在一起?顯然這不支持... http://stackoverflow.com/questions/6859868/popping-viewcontroller-doesnt-call-viewwillappear-when-going-back – RonLugge