1

私はあるUINavigationController時点で 2 番目のビューをプッシュ ( navigationcontroller pushViewController: animated:) し、後で 3 番目のビューをプッシュするビュー コントローラー ( ) を持っていますpopToRootViewController: animated:。問題は、ビューがルート ビューに戻された後、viewWillApperルート ビューのメソッドが呼び出されないことです。それをチェックするためにいくつかのブレークポイントを設定しましたが、通過していません。に配置されたルートビューの一部のコンテンツをリロードする方法がありviewWillApperpopToRootViewController: animated. 何が起こっているのか分かりますか?

ありがとう

4

2 に答える 2

0

デリゲート メソッドを使用して、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];
}

これが最善の解決策であると提案しているわけではありませんが、私にとってはうまくいきました!

于 2015-10-20T08:20:13.183 に答える