在 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];
}
我并不是说这是最好的解决方案,但它对我来说是一种享受!