UINavigationController、UITableView、および次のビューを表示しない
-
06-07-2019 - |
質問
テーブルに問題があり、ユーザーがテーブルのセルにタッチすると別のビューが表示されます。メインビューにUITabBarControllerを使用して、さまざまなビューを表示しています。次に、ユーザーがUITableViewビューを選択するときにUINavigationControllerを使用して、テーブルセル選択から次のビューを表示します。
これは問題です。テーブルセルを選択すると、セルが強調表示され、次のビューが表示されません。 IBを使用しています。私が見つけたすべての例は、例が機能することを除いて、私と同じようにしています!
辞書を使用してNSMutableArrayにコントローラーをロードしました。また、配列項目を使用するのではなく、View Controllerを直接作成してこのコードを試しました。同じ結果....
ターゲットコントローラー(Calc1ViewController)をチェックして、コントローラーに問題がないことを確認しました。直接表示すると、コントローラー(Calc1ViewController)が正しく表示されます。
ここにコードがあります.....
辞書内のView Controllerの初期化:
Calc1ViewController *calc1ViewController = [[Calc1ViewController alloc] init];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"SSC - page 1",@""), @"title",
calc1ViewController, @"viewController",
nil]];
[calc1ViewController release];
また、辞書を使用せずにこれを試しました-[[menuList objectAtIndex:...];の代わりにView Controllerを作成します;行-次のようなView Controllerを作成します:
Calc1ViewController *targetViewController = [[Calc1ViewController alloc] init];
// the table's selection has changed, switch to that item's UIViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:@"viewController"];
[[self navigationController] pushViewController:targetViewController animated:YES];
targetViewController = nil;
}
Navigation ControllerはAppDelegateで定義され、IBを介してRootViewControllerに接続されます。
テーブル行を選択すると、デバッガーにpushViewControllerコードが実行されていることが表示されますが、次のビューは表示されません。次に例を示します。
代替テキストhttp://thecoolestcompany.com/ssc-table-view.jpg
アイデアはありますか
解決
最終的にそれを理解しました......
同じレベルにUINavigationControllerとUITabBarControllerがありました。 Navigation ControllerをTab Bar Controllerの子として移動した後、すべてが機能しました。必要な数のNavigation ControllerをTab Barに追加できます。 IBでは少しわかりにくいです。 NavigationControllerをTabBarにドラッグして、新しいTab Barアイテムとして使用する必要があります。
他のヒント
あなたが提供したコードを使うことはあまりありません。他のコードを見なくても考えることができるのは、View Controller(辞書にあるもの)を正しく初期化していないか、まったく初期化していないか、アクセスしている辞書が正しくないことです...
pushViewControllerが呼び出されたときの[self navigationController]の値は何ですか。ゼロですか?
pushViewControllerに渡されたときのtargetViewControllerの値は何ですか。ゼロですか?