iPhoneアプリで画面遷移がうまくいかない問題について

このQ&Aのポイント
  • iPhoneアプリを開発中ですが、画面遷移がうまくいきません。
  • タッチイベント内で画面を切り替えたいのですが、エラーメッセージが表示されてしまいます。
  • 初心者なのでどう手をつければ良いかわかりません。助けてください。
回答を見る
  • ベストアンサー

objective-c 画面遷移について

今、iPhoneアプリを開発しています。簡単なカードゲームですが、 画面遷移について困っています。 サブクラス内のタッチイベントに、 [super presentModalViewController:viewController animated:YES]; と記述し、画面を切り替えたいのですが、 「'UIView' may not respond to 'presentModalViewController : animated:'」と 注意メッセージが表示され、 また、実行すると「Thread 1: received signal: "SIGABRT"」 となり、落ちてしまいます。 何分、初心者なもので、どこからどう手をつけたら良いのか分かりません。 色々調べたのですが、中々該当する答えが見つかりませんでした。 どなたか、お分かりになる方教えて頂けないでしょうか。 宜しくお願いします。

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

  • ベストアンサー
  • harawo
  • ベストアンサー率58% (3742/6450)
回答No.1

警告文そのままです。「super」はなんですか?UIViewControllerのインスタンスなら、この警告文は出ないでしょう。「UIViewは、このメソッドに反応しませんよ」といわれるのですから、おそらくUIViewのインスタンスなのでしょう。 http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentModalViewController:animated:

関連するQ&A

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

    プログラミングに関して素人です。 UIViewControllerからPushコードを使って別のUIViewに画面遷移したいのですが 遷移先にTableViewを2つ並べております。 画面遷移する際のコードはどのように記述したらいいのでしょうか? 詳しいかたお力お貸しいただければと思います。 ViewController.m - (IBAction)NewsPage:(UIButton *)sender { //こちらの記述方法が不明 } TViewController.h // XibファイルとUIViewの紐づけ。 @property (weak, nonatomic) IBOutlet UITableView *leftTableView; @property (weak, nonatomic) IBOutlet UITableView *rightTableView; - (IBAction)TopButton:(UIButton *)sender; 根本的になにか違えばご指摘お願いします。

  • 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]; }

  • 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と同じタイミング(アプリがアクティブになったとき)で画面遷移を行う方法はありますでしょうか?

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

    毎回、初歩的な質問内容で申し訳ありませんが、困っているので教えて下さい。 「FirstViewController」はUIScrollViewでスクロールさせている画面で、タッチイベントを取得する為に UIScrollView のサブクラスを作っています。 そこでタッチすると、「SecondViewController」へ固定の画面で遷移するようにしたいのですが、「SecondViewController」の画面もそのままスクロール画面で表示されてしまいます。。。 「SecondViewController」をスクロールさせず、位置x=0 y=0で表示させるにはどうしたら良いのでしょうか? 詳しく教えて頂けると、大変助かります。。 ↓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 *svc; svc = [[SecondViewController alloc] init]; [self addSubview:[svc view]]; }

  • UIImageViewをタップで、画面遷移するには

    iphoneのアプリ開発のなかでわからない部分があるので、投稿しました。 UIViewControllerクラスのサブクラス(Nomal_topViewController)の上に、UIViewクラスのサブクラス(PreviewView)の上に、UIImageViewのサブクラス(TapImage) というレイヤー順で表示しているのですが、TapImageをタップした際、新しいViewControllerを開く、もしくは全画面表示のViewを開く。という処理を行いたいのですが、どのような処理を実装すればよいのでしょうか? TapImageでタップは検出できています。 わかる方いましたら、ご返答よろしくお願いします。

  • Objective-C,viewが動作しない

    IBを使わないカメラアプリを作っています。 AppDelegate.m内のapplication didFinishLaunchingメソッド内で生成したwindowとviewはコンパイルして表示確認できたのですが、viewControllerで書いたUIImagePickerViewControllerのviewが出てきません。 そもそもviewController.mのloadViewメソッドやviewDidLoadメソッドが動いていません。(メソッド内にNSLogを書いてコンパイルしてもログに出ない) viewController.h #import <UIKit/UIKit.h> @interface CameraViewController : UIViewController <UINavigationControllerDelegate,UIImagePickerControllerDelegate> { @private UIImagePickerController* _imagePicker; } @property(nonatomic,retain) UIImagePickerController *imagePicker; @end viewController.m #import "CameraViewController.h" @implementation CameraViewController @synthesize imagePicker=_imagePicker; - (void)dealloc { [super dealloc]; } #pragma mark - View lifecycle - (void)loadView { [super loadView]; //UIImagePickerControllerの作成 if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ return; } UIImagePickerController* imagePicker; imagePicker = [[UIImagePickerController alloc] init]; [imagePicker autorelease]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.allowsEditing=NO; imagePicker.delegate = self; //imagePickerのviewを最上部に [self presentModalViewController:imagePicker animated:YES]; //シャッターを切る [self.imagePicker takePicture]; } @end viewControllerが機能しない原因としてそういった可能性が考えられるのでしょうか? あれこれ調べてみましたが煮詰まっています。よろしくお願いします

  • 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は使っていません。

  • objective-cでの引数について

    お世話になります。 引数の使い方について以下の様な事が可能なのか分からなくて困ってしまい質問します。 検索等は行いましたが目的のものが見つからなかったので、、 以下ですが、あるボタンをタップすると、buttonDidPushを実行するプログラムがあったとします。 @implementation ViewController -(void)viewDidLoad{ ~中略~ [button addTarget: self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)buttonDidPush{    処理 } @end ここで聞きたいのは、 ボタンのところで、引数(数値変数 x )をbuttonDidPushに持っていくことができるかどうかなのですが、 例えば以下のように変更しました。 action:@selector(buttonDidPush) ↓ action:@selector(buttonDidPush:x:) -(void)buttonDidPush{ ↓ -(void)buttonDidPush(Integer)x{ としましたが、build successで一応シミュレータは動きましたが、 ボタンをタップするとmain.mのほうでエラーが出てしまい動きませんでした。 なんとなく文法が間違ってるんじゃないかと思いますが、どこか心当たりのある方、よろしくお願いいたします。 尚、数値xはintで宣言済みです。 main.mでのエラー内容は int retval = UIApplicationMain(argc, argv, nil, @"testAppDelegate"); のラインで、「Thread1:Program received signal: ""SIGABRT.」と出ていました。 また、私自身が何かobjective-cの文法について重大な勘違いをしている可能性もあります・・

  • 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]; }

  • [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]; //読み込んで追加========================= } お手数ですが、ご教授いただけましたら幸いです。