iPhoneアプリのNavigationControllerでの画面遷移後、戻るボタンをカスタマイズする方法について

このQ&Aのポイント
  • iPhoneアプリの開発でNavigationControllerで画面遷移した後、左上に表示させる戻るボタンをカスタマイズする方法を知りたいです。
  • AppDelegateクラスなどで一括で設定する方法を試しましたがうまくいきません。
  • UIBarButtonItemを使って戻るなどの文字を非表示にし、矢印だけの表示にしたいです。ViewContorollerのクラス内に書くのは面倒なので、分かる方がいたら教えてください。
回答を見る
  • ベストアンサー

NavigationItemに関する質問です。

iPhoneアプリの開発でNavigationControllerで画面遷移した後、左上に表示させる戻るボタンをカスタマイズしたいです。 実際に方法は心得ているのですが、これをAppDelegateクラスなどで一括で設定したいのですがうまくいきません。 UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = back; 上記の様に戻るなどの文字は表示せず、矢印だけの表示にするつもりです。 それぞれのViewContorollerのクラス内に書くのはかなり面倒なので、分かる方がいたら教えてくださると助かります。

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

UIViewControllerを継承した派生クラスを作り、 その中で戻るボタンをカスタマイズするコードを書き、 各ViewControllerクラスは、そのクラスから派生させれば よいと思います。

関連するQ&A

  • iPhoneアプリ とあるプログラムの質問です。

    色々調べたり、書き換えてみたりしたのですが、原因がいまいちよくわかりません。お手上げなので質問させていただきます。 Nabigation-Basedのアプリ製作の中で、テーブル表示から下層画面を選択して、画面遷移をするためのプログラムをRootViewController.mに書いているのですが、シミュレータで実行すると [self.navigationController pushViewController:detailViewController animated:YES]; で、Thread1:Program received signal:"SIGABRT"の表示がでます。(iOS 4.1です) 考えられる原因は何があるでしょうか。ヒントでも構いませんのでよろしくお願い致します。前後の文は下記です。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { indexPath.section == 0 ; if( indexPath.row == 0 ) { cal_1_UIViewController *detailViewController = [[cal_1_UIViewController alloc] initWithNibName:@"cal_1_UIViewController" bundle:nil]; ☆☆☆[self.navigationController pushViewController:detailViewController animated:YES];☆☆☆→エラーがでます。 [detailViewController release]; }else if( indexPath.row == 1 ) { cal2_UIViewController *detailViewController = [[cal2_UIViewController alloc] initWithNibName:@"cal2_UIViewController" bundle:nil]; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; }else if( indexPath.row == 2 ) { cal3_UIViewController *detailViewController = [[cal3_UIViewController alloc] initWithNibName:@"cal3_UIViewController" bundle:nil]; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; }

  • 【iphoneアプリ開発】ボタン&処理の共通化

    突然の質問失礼致しますm(_ _)m ナビゲーションバーを使用したアプリを作っています。 右に「使い方」の画面へ遷移するUIBarButtonItemを配置したいと考えております。 このとき、各画面のボタンの配置、遷移したときのアクションを書けば 遷移できるのは確認できたのですが、全てのページにそれを書くのがあまり よくないような気がしています。 ボタンとボタンのアクションを共通化することは可能でしょうか? また、その場合どのファイルにどのように書くのが後々の変更等にも耐えやすいでしょうか? (例えば、「使い方」ボタンを「設定」ボタンに変更する等。。。) 実装しているボタンとボタンのアクションのソースは以下になります。 //ボタンの配置(viewDidLoad) UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"使い方" style:UIBarButtonItemStylePlain target:self action:@selector(howtoButtonTouched:)]; self.navigationItem.rightBarButtonItem = btn; //ボタンのをタップしたときのアクション -(void)howtoButtonTouched:(id)sender { //使い方画面へ遷移 HowtoViewController *howtoViewController = [[HowtoViewController alloc] init]; [self.navigationController pushViewController:howtoViewController animated:YES]; } どなたか、良い方法があればご教授頂けますと 大変ありがたいです。

  • iPhoneアプリの開発についてです。

    UINavigationControllerのルートに紐づけられたBookMarkViewControllerというビューがあります。 このBookMarkViewControllerはテーブルビューで、 (1) BookMarkViewController *nextDir = [[BookMarkViewController alloc] init]; [self.navigationController pushViewController:nextDir animated:YES]; 上記のようなコードで、次々と画面遷移していきます。 また、BookMarkViewControllerには、 (2) BookMarkViewController *move = [[BookMarkViewController alloc] init]; move.isMove = YES; UINavigationController *nav = [self.storyboard instantiateViewControllerWithIdentifier:@"BookMarkView"]; [nav setViewControllers:[NSArray arrayWithObjects:move, nil]]; [self presentViewController:nav animated:YES completion:nil]; 上記のような内容のメソッドがあり、次々と画面遷移することのできる新たなUINavigationControllerをモーダル表現で表示します。 画面遷移する前のBookMarkViewControllerでは、上記のコードでうまくモーダルがでるのですが、(1)のメソッドを実行し新たに作り遷移したBookMarkViewControllerではなぜか、 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <BookMarkViewController: 0x11822e070>.' というエラーが吐き出されうまくいきません。 (2)のメソッドで「nav」を生成した直後にnav.viewControllersをNSLogしてみたのですが、nullがかえされてしまいました。(成功した例では<BookMarkViewController ○○○>と、正常に表示されました) 誰かわかる方ご指摘お願いします。

  • iPad NavigationにSplitView

    Navigation Basedアプリで、画面遷移してSplitViewを表示したいのです。 以下を参考に、Viewを切り替えてのSplit Viewの表示はできました。 http://temping-amagramer.blogspot.com/2010/09/ipadobjective-c.html LeftTableViewController *lefttableviewcontroller = [[LeftTableViewController alloc] initWithStyle:UITableViewStylePlain]; LeftNavigationController *leftnavigationcontroller = [[LeftNavigationController alloc] initWithRootViewController:lefttableviewcontroller]; RightViewController *rightviewcontroller = [[RightViewControlleralloc] initWithNibName:nil bundle:nil]; RightNavigationController *rightnavigationcontroller = [[RightNavigationController alloc] initWithRootViewController:rightviewcontroller ]; MainSplitViewController *mainsplitviewcontroller = [[MainSplitViewController alloc] init]; mainsplitviewcontroller.viewControllers = [NSArray arrayWithObjects:leftnavigationcontroller,rightnavigationcontroller,nil]; [self.view addSubview:mainsplitviewcontroller.view]; これで、最後の addSubviewしている箇所を [self.navigationController pushViewController:mainsplitviewcontroller animated:YES]; と書き換えれば、Navigation Baseed アプリにも Split Viewが表示されるのでは? と考えたのですが、エラーも出ずにスルーされます。 ちなみに、Split View関連のソースをコピーして、別プロジェクトでsubViewとして表示されるので、 Split View自体のコードは正そうです。 悪い箇所を教えていただけますでしょうか。

  • Objective-c 画面遷移について

    やはり、画面遷移ではまっていますので、助けて下さい。 navigationControllerで作成しています。 (内容は以前に質問させて頂いているものとほぼ同じですが、) 「FirstViewController」はUIScrollViewでスクロールさせている画面で、タッチイベントを取得する為に UIScrollView のサブクラスを作っています。 そこでタッチすると、「SecondViewController」へ遷移するようにしたいのですが、下記のように単純にpushViewControllerを使ってサブクラスへ書くと、「Property 'navigationContoroller' not found on object of type 'MyScrollview'」というエラーが表示されてしまいます。 このクラスへ書いたらいけないというのは、なんとなく分かりますが、かと言って何からどう手をつければ良いのか分かりません…… 問題なく画面遷移させるにはどうしたらよいのでしょうか。 詳しく教えて頂けると、大変助かります。。 ↓FirstViewController.h↓ @interface FirstViewController : UIViewController{   MyScrollview *controller; IBOutlet UIScrollView *scrollView; } ↓FirstViewController.m↓ - (void)viewDidLoad { controller = [[ MyScrollview alloc] initWithFrame:CGRectMake(0, 0, 1100, 1100)]; self.view = controller; [super viewDidLoad]; [super loadView]; scrollView.contentSize = controller.frame.size; [scrollView addSubview:controller]; } ↓MyScrollview .h↓ @interface MyScrollview : UIView<UIScrollViewDelegate>{ } @end ↓MyScrollview .m↓ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{ ~省略~ SecondViewController *mvc = [[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease]; [self.navigationController pushViewController:mvc animated:YES]; }

  • [objective-c]他クラスのメソッドを呼ぶ

    objecive-cを使ってアプリを作っているのですが、 iphoneアプリの開発初心者です。 action.mファイルで指定しているボタンのアクションのところで、 kekka.mのファイルに書いているメソッドを実行させたいのですが、 他クラスのメソッドの実行方法が分かりません。 [インスタンス メソッド名]; で実行できるということは何となく分かったのですが、 どれがインスタンスに当たるのかが不明で、質問しました。 action.mに書いたメソッド ------------------- //次へのボタンが押されたときの処理 - (IBAction)kaisetsu:(id)sender { //kekka.mの- (void)showNextメソッドを呼び出したい。 [★ここの書き方が分かりません★]; kekka *viewController = [[kekka alloc] initWithNibName:@"kekka" bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; [navigationController setNavigationBarHidden:YES animated:YES]; //モーダルビューとして、次のビューを表示する [self presentModalViewController:navigationController animated:YES]; } ------------------- kekka.mに書いているメソッド ------------------------ // 結果を表示する - (void)showNext { // 結果情報を取得する QuizItem *item = [self.quiz nextQuiz]; self.questionTextView.text = item.question; //読み込んで追加========================= NSUserDefaults *_userDefaults = [NSUserDefaults standardUserDefaults]; NSString *kaisetsutext; kaisetsutext = [_userDefaults stringForKey:@"kaisetsutext"]; //読み込み kaisetsutext = item.kaisetsu; [_userDefaults setObject:kaisetsutext forKey:@"kaisetsutext"]; [_userDefaults synchronize]; //読み込んで追加========================= } お手数ですが、ご教授いただけましたら幸いです。

  • iPhoneアプリの開発についてです。

    元のビューからモーダルで表示させるビューに画面遷移に伴い値を受け渡したいのですがうまくいきません。 私は主に画面遷移する際 ○○○ *△△△ = [self.storyboard instantiateViewControllerWithIdentifier:@"□□□"]; [self presentViewController:△△△ animated:YES completion: nil]; とコーディングしています。 インスタンス生成部分を ○○○ *△△△ = [[○○○ alloc] init]; とすれば簡単に値が受け渡しできるのですが、storyboadで作ったような表示になりません。(セルの高さが違う、ラベルが表示されないなど) グローバル変数などを使っても解決できますが、なるべく複雑にはしたくありません。 ご指摘お願いします。

  • Xcodeでの画面遷移について

    Xcode5.0でアプリを作成しています。 アプリがバックグラウンドから再びアクティブになるときに画面遷移の処理をするために 以下の方法にてAppDelegateのapplicationDidBecomeActiveからView Controllerに処理を渡しています。 AppDelegate.m - (void)applicationDidBecomeActive:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName:@"applicationDidBecomeActive" object:nil]; } ViewController.m { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:@"applicationDidBecomeActive" object:nil]; } - (void)applicationDidBecomeActive { ViewController *View = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondView"]; [self presentModalViewController:View animated:YES]; } ViewController.mの- (void)applicationDidBecomeActiveで画面遷移の処理をしたいのですが、ViewDidAppearでは出来る画面遷移がapplicationDidBecomeActiveでは実行されない状態です。 ググって調べたところ、読み込みのタイミングが問題らしいことはなんとなく解ったのですが、 どうにかして、- (void)applicationDidBecomeActiveと同じタイミング(アプリがアクティブになったとき)で画面遷移を行う方法はありますでしょうか?

  • xcodeでのiOS開発で、コードで画面遷移する時

    xcodeでのiOS開発で、コードで画面遷移する方法について質問です。 テーブルビューで、セルをタップすると呼び出されるメソッドで コードで画面遷移をさせようとしています。 しかし、画面遷移をすると遷移先の画面が真っ黒になってしまいます。 どうすればなおりますか? - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NextViewController *nvc = [[NextViewController alloc] init]; nvc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:nvc animated:YES]; } ちなみに、遷移先のクラスはインポートしてあります。 StoryBoardは使っていません。

  • [iPhoneアプリ開発]継承クラスを作らず

    Objective-cでiPhoneアプリを作っています 自前でクラスを作らず(.hファイルと.mファイルを作らず)別のファイルで基本的なクラスのインスタンスを作ってその場で設定したいんですが、どうすればいいでしょうか。 例えば、ある画面のコード(ViewController.mにします)で UITableViewController *foo = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped]; (TableViewを表示させたい) と書き、その画面(ViewController)内のボタンやラベルを押せばfooに遷移できるようにします。 すると、確かに遷移はできるのですが何も無いページが表示されるだけです。 TableViewなので設定(セクションのタイトルだとかセルの数だとかを決める)をしなければ何も表示されないのは当たり前ですよね。 この設定をViewController.m内で行いたいのです。 いつもならUITableViewControllerを継承したクラスを作りそこで設定を行なっていました。 今回はそれを作りたいくない、というわけです。 できますでしょうか。 ちなみに遷移に関してですが、NavigationControllerを想定しています。 よろしくお願いします。