UINavigationController に関する問題があります。私がやっていることは、1 つのビュー コントローラーを処理する 1 つのナビゲーション コントローラーをセットアップし、それに A という名前を付けることです。次に、ビュー コントローラー A に UIView を配置し、そのビューの上にテーブルビューを配置します。tableViewcontroller とそのデリゲートは、別のクラスで定義されます。今私がしたいのは、ユーザーがテーブルセルをクリックしたときに、「pushViewController」メソッドを使用して新しいビューコントローラーをプッシュすることです。ナビゲーションコントローラーへの参照をテーブルビューコントローラーまでずっと渡す必要がありますか? または、tabelviewcontroller クラスからナビゲーション コントローラーを取得する方法を教えてください。
2 に答える
1
別の UITableViewclass で、UITableViewDelegates がある場所で (yourTableView) と言い、プロパティを宣言しid delegate;
ます viewController から A ,subject と言いますyourTableView.delegate = self;
そしておそらく、didSelect をプッシュするための yourTableViewClass の didSelectRowAtIndexPath で、常に最後にプッシュされる newController のインスタンスを作成します (例: newController)。
[delegate.navigationController pushViewController:newController animated:YES];
ここで、「デリゲート」は、すでに UINavigationController を割り当てた viewController A であることがわかります。これがうまくいくことを願っています
于 2012-09-27T14:48:54.767 に答える
1
これは、私が機能させることができたチュートリアルです。
トピックに関する公式の SDK ドキュメントも読みました: Combining Tab Bar and Navigation Controllers。私はまだ学習中なので、チュートリアルはドキュメントよりも役に立ちました。
それ以外の場合は、このコードを試してください
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create instance of UINavigationController
UINavigationController *myNavigationController;
// Create initialized instance of UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// Create initialized instance of NSMutableArray to hold our UINavigationControllers
NSMutableArray *tabs = [[NSMutableArray alloc] init];
// Create first UIViewController
UIViewController *myFirstViewController = [[UIViewController alloc] init];
[myFirstViewController setTitle:@"First"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[myFirstViewController release], [myNavigationController release];
// Create second UIViewController
UIViewController *mySecondViewController = [[UIViewController alloc] init];
[mySecondViewController setTitle:@"Second"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[mySecondViewController release], [myNavigationController release];
// Add the tabs to the UITabBarController
[tabBarController setViewControllers:tabs];
// Add the view of the UITabBarController to the window
[self.window addSubview:tabBarController.view];
}
于 2012-09-27T14:34:18.533 に答える