2

私はUIViewController *vc14つのボタンを持っています。各ボタンは、別のボタンへのプッシュ セグエを引き起こしますUIViewController *vc2vc2どのボタンが押されたかに基づいて、いくつかの情報が表示されます。からの情報vc1vc2inに渡します(単なる int 値)。これはすべてうまくいきます。ここで、iPhone がオン( isVisible ) で aを受信した場合 (Bluetooth デバイスで何かが発生した場合) も呼び出されるようにする必要があります。これが私のコードです:vc1prepareForSeguevc2vc1vc1vc1UINotification

-(void) eventDetected:(NSNotification *)notification{
    if(self.isViewLoaded && self.view.window){
        [self performSegueWithIdentifier:@"detected" sender:self];
    }
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    VC2 *destination = [segue destinationViewController];
    [destination setValue:value];
}

現在、適切なイベントが発生した場合、vc21 回ではなく 2 回ロードされます。そして、出力ログに次のエラー メッセージが表示されます。

「ネストされたプッシュ アニメーションにより、ナビゲーション バーが破損する可能性があります」 & 「.corrupted の外観トランジションを開始/終了するための不均衡な呼び出し」 & 「予期しない状態でナビゲーション トランジションを終了する。ナビゲーション バーのサブビュー ツリーが破損する場合があります。

これらのエラーは、戻るボタンを押した後に発生します。NSLogステートメントを追加したため、が毎回 2 回呼び出されることvc2がわかっています。viewDidLoad

ストーリーボードを使用して、4 つのボタンすべてのプッシュ セグエを作成しました。私はそれらにラベルを付けていません。ストーリーボードを通じてイベント プッシュ セグエも作成し、識別子を付けました"detected"。ここにいる誰かが、私が間違っていることについて何らかの考えを持っていることを願っています. アドバイスをいただければ幸いです。ありがとう。

現在のコードは次のとおりです。

-(void)viewDidAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exerciseDetected:) name:@"ExerciseDetected" object:nil];
    [[NSNotifcationCenter defaultCenter] addObserver:self selector:@selector(cancelExercise:) name@"cancelExercise" object:nil];
}
-(void)exerciseDetected:(NSNotification *)notification{
    if(self.isViewLoaded && self.view.window){
        if(self == self.navigationController.topViewController){
            if(!timerRunning){
                timerRunning =YES;
                _exerciseTimer = (NSTimer scheduledTimerWithTimeInterval:EXERCISE_AUTOSTART_TIME target:self selector:@selector(startExercise:) userInfo:nil repeats:NO];
            }
        }
    }
}
-(void)cancelExercise:(id)sender{
    [_exerciseTimer invalidate];
    timerRunning = NO;
}
-(void) startExercise: (id)sender{
    timerRunning = NO;
    [self performSegueWithIdentifier:@"detected" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     vc2 *destination = [segue destinationViewController];
    [destination setSElectedExerciseIDFromMenu:_selectedExercise];
}
4

1 に答える 1