上の写真は私のアプリのスキーマを示しています..UIViewController3のコンテンツを1と2で表示するカスタムビューを作成しました。
VC1と2でカスタムビューに触れたときにVC4に直接ジャンプしたい。
カスタムビューはUIViewでしたが、Touchイベントを受信するためにInterfaceBuilderでUIControlに変更しました。
カスタムビュークラスのtoucheventメソッドで次のコードを使用しました
- (IBAction)customViewTouched:(id)sender {
VC4 *nextController = [[VC4 alloc] initWithNibName:@"VC4" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:nextController];
[self presentViewController:navigationController animated:YES completion:nil];
navigationController.navigationBar.tintColor = [UIColor blackColor];
navigationController.navigationBar.topItem.title = @"My Title";
navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];
navigationController.navigationItem.hidesBackButton = FALSE;
// navigationController.navigationBar.backItem.title = @"back";
}
VC2でカスタムビューがタッチされたとき(正しく呼び出されます)-VC4がポップしますが、カスタムビュー内でのみ発生します。
また、ナビゲーションバーに戻るボタンが表示されません。(他のstackoverflowの回答で示唆されているように、ViewDidLoadでカスタムビューのタイトルも設定してみました)
3. customViewのサイズのダミーUIButtonをVC1に作成し、その中にcustomViewを配置して、VC1自体でタッチイベントを処理できるようにします。これにより、パフォーマンスの問題が発生しますか?
[myCustomViewButton addTarget:self action:@selector(myEventHandler) forControlEvents: UIControlEventTouchUpInside];
上記のコードを使用すると、エラーはスローされませんが、「UIViewController」クラス名を使用すると、「self」ではなくaddTargetでメソッドmyEventHandlerが呼び出されることはなく、エラーがスローされます。
私はこれを進める方法がわかりません..どんな助けもありがたいです:)