UINavigationControllerを使用して、UIViewControllerをプッシュ/ポップしています。場合によっては、ルートView Controllerにポップして、少し遅れてView Controllerをプッシュしようとしています(0.1f)。
メッセージビューコントローラのプッシュコードは次のとおりです。私のアプリは2つの通知を発行します。1つ目はタブを選択し、2つ目は正しいViewControllerをそのタブのスタックにプッシュします。
//user taps a button and the app needs to switch tab and push the correct viewController
//onto the tab. I have tried setting pop == NO to avoid a 'double pop' but I still get
//overlapped titles
-(IBAction)messages:(id)sender {
NSDictionary* dictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSNumber numberWithInt:4], [NSNumber numberWithBool:YES] , nil] forKeys:[NSArray arrayWithObjects:@"tab",@"pop", nil]];
[[NSNotificationCenter defaultCenter] postNotificationName:kAutoSelectTab object:dictionary];
[[NSNotificationCenter defaultCenter] performSelector:@selector(postNotificationName:object:) withObject:kMessages afterDelay:0.1f];
}
//responds to the first notification
-(void)autoSelectTab:(NSNotification*)notification {
NSDictionary* dictionary = (NSDictionary*)[notification object];
int tab = [[dictionary objectForKey:@"tab"] intValue];
BOOL pop = [[dictionary objectForKey:@"pop"] boolValue];
[self.tabBarController setSelectedIndex:tab];
UIViewController* vc = [[self.tabBarController childViewControllers] objectAtIndex:tab];
PSLogDebug(@"Selecting tab:%@",[vc class]);
[self tabBarController:self.tabBarController didSelectViewController:vc];
if (pop == YES) {
if ([vc isKindOfClass:[UINavigationController class]]) {
[(UINavigationController*)vc popToRootViewControllerAnimated:YES];
}
}
}
//responds to the second notification
-(IBAction)messages:(id)sender {
[self.navigationController popToRootViewControllerAnimated:NO];
MessagesViewController* vc = [[MessagesViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
機能的には、ビューはポップして正しくプッシュされているように見えますが、タイトルはポップせず、新しいタイトルはそれぞれ古いタイトルの上にオーバーレイされます。
viewDidLoadで各ビューコントローラーのタイトルを設定しました
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.title = @"More";
}
ルートへのポップ、遅延、プッシュを試みない場合、タイトルとビューは重複することなく期待どおりに動作します。
スクリーンショットからのサンプル画像
私はスタックオーバーフローについてよく掘り下げましたが、私が抱えている問題と同じ問題を説明する質問は見当たりません。
Qn.1:popToRoot、Delay、push Viewアプローチに根本的に間違っている点はありますか?Qn.2:誰かが以前にこの種の行動を見たことがある場合、どのようにそれを解決しましたか?