タイトルを設定し、ナビゲーション バーにバー ボタンを追加する際に、奇妙な問題が発生しています。
私のアプリはタブ付きアプリケーションです。問題は私の最初のタブにあります。最初のタブは、UITableViewController を含む UINavigationController で構成されています。私のAppDelegateから:
UIViewController *firstViewController = [[MyTableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
_tabBarController = [[TFTabBarController alloc] init];
_tabBarController.delegate = self;
_tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];
firstViewController で行を選択すると、UIWebViewController をナビゲーション スタックにプッシュします。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *secondViewController = [[MyWebViewController alloc] init];
[self.navigationController pushViewController:secondViewController animated:YES];
}
WebView でハイパーリンクの onclick をインターセプトすると、別の UITableView をナビゲーション スタックにプッシュします。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
UIViewController *thirdViewController = [[MyTableViewController alloc] init];
[self.navigationController pushViewController:thirdViewController animated:YES];
return NO;
}
return YES;
}
thirdViewController が開くと、そのナビゲーション バーには、戻るための前のビューのタイトルが付いた戻るボタンのみが含まれます。タイトルと右バーのボタンが表示されていません...
これは私がそれらを表示しようとする方法です:
self.title = @"My Title";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push me" style:UIBarButtonItemStylePlain target:self action:@selector(push)];
また、navigationController を介してボタンを設定しようとしましたが、まだうまくいきません:
self.navigationController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push me" style:UIBarButtonItemStylePlain target:self action:@selector(push)];
ここで何が間違っているのでしょうか?