• 締切済み

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

みんなの回答

回答No.1

遷移先の画面が真っ黒になるんだから、 遷移先の画面(NextViewController)を どのように作ったのか説明しないと 誰もわからないでしょう。 とりあえず、背景色も背景画像も何も設定しない ものを作ったのだったら、真っ黒画面が表示されます。 Storyboardを使っている場合は、白の背景色が あらかじめ設定された画面が最初に作られますが、 コードで生成するならそのあたりも自分でちゃんと 設定する必要あります。

関連する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アプリ開発についての質問です

    tableviewcellにチェックマークを付けるだけの簡単なコードですが、なぜかチェックマークを付けたセルとは別のセルにまでチェックマークがついてしまっています。 また、激しくスクロールするとさっきまで付いていたチェックマークが外れていたりとさらに酷い状態に・・・。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType == UITableViewCellAccessoryCheckmark) cell.accessoryType = UITableViewCellAccessoryNone; else cell.accessoryType = UITableViewCellAccessoryCheckmark; [tableView deselectRowAtIndexPath:indexPath animated:YES]; } いろんなサイトで見ても上記のコードが最もよく見るコードでした。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"ButtonCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; [self updateCell:cell :CellIdentifier atIndexPath:indexPath]; return cell; } - (void)updateCell:(UITableViewCell *)cell :(NSString *)CellIdentifier atIndexPath:(NSIndexPath *)indexPath { BButton *type = (BButton *)[cell viewWithTag:1]; //Buttonはライブラリを使用 [ReturnButton typeButton:type :self.showArr[indexPath.row]]; } チェックマーク以外はUIButtonなども正常に表示されました。 心当たりがあればお願いします。

  • iPhoneアプリ 画面遷移での変数受け渡し

    現在、iPhoneアプリの開発を勉強している者です。 少し詰まってしまった箇所があるので、ご教授いただけると幸いです。 TableViewController間での変数の受け渡しを実装しており、1枚目のTableViewでタップされたセルのテキストを2枚目に渡す、というコードを書きました。 受け渡しに関するコードは以下の部分です。 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"mySegue" sender:self]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"mySegue"]) { SecondTableViewController *viewCon = segue.destinationViewController; NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; viewCon.myValue = cell.textLabel.text; } } これ自体は問題なく動いてくれたのですが、SecondTableViewControllerにNavigationControllerをEmbed Inしたところ、1枚目でセルをタップした際にエラーが出てアプリが止まってしまうようになりました。 BreakPointを設けてみると上記コードのviewCon.myValue = cell.textLabel.text;のところで止まっており、unrecognized selector sent to instanceというエラーが吐き出されていました。 同様のエラーが出た例などを調べてみたのですが自力では解決できず・・・、どなたか原因を指摘して頂けるとありがたいです。 よろしくお願いします。

  • Objective-CのTableViewについて

    つまづいてなかなか先に進めません。回答の方をよろしくお願いします。 [ソース] - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { switch ([indexPath section]) { case 1: { switch ([indexPath row]) { case 0: { DropDownCell *cell = (DropDownCell*) [tableView cellForRowAtIndexPath:indexPath]; NSIndexPath *path0 = [NSIndexPath indexPathForRow:[indexPath row]+1 inSection:[indexPath section]]; NSIndexPath *path1 = [NSIndexPath indexPathForRow:[indexPath row]+2 inSection:[indexPath section]]; NSIndexPath *path2 = [NSIndexPath indexPathForRow:[indexPath row]+3 inSection:[indexPath section]]; NSArray *indexPathArray = [NSArray arrayWithObjects:path0, path1, path2, nil]; if ([cell isOpen]) { [cell setClosed]; dropDown1Open = [cell isOpen]; [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop]; } else { [cell setOpen]; dropDown1Open = [cell isOpen]; [tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop]; } break; } default: { dropDown1 = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text]; NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:[indexPath section]]; DropDownCell *cell = (DropDownCell*) [tableView cellForRowAtIndexPath:path]; [[cell textLabel] setText:dropDown1]; NSIndexPath *path0 = [NSIndexPath indexPathForRow:[path row]+1 inSection:[indexPath section]]; NSIndexPath *path1 = [NSIndexPath indexPathForRow:[path row]+2 inSection:[indexPath section]]; NSIndexPath *path2 = [NSIndexPath indexPathForRow:[path row]+3 inSection:[indexPath section]]; NSArray *indexPathArray = [NSArray arrayWithObjects:path0, path1, path2, nil]; [cell setClosed]; dropDown1Open = [cell isOpen]; [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationTop]; break; } } } } [tableView deselectRowAtIndexPath:indexPath animated:YES]; } このようなプログラムを書いたのですが、 UITableViewのCellがなぜか反転してしまいます。 つまり、画像のような状態になった後、再びCellを押すと閉じ、さらに押すともう一度画像のような状態になるのですが、Object1 → Object3 という状態から Object3 → Object1 と順番が逆になってしまうのです。 全く理由がわかりません。ぜひとも回答の方をお願い致します。 初めての投稿ですので、どのように説明していけばいいのかわかりませんでした。 ですが、どうしても直したい問題ですので、よろしくお願い致します。

  • itunesStoreに画面遷移せず移動する方法

    tableView上の選択行から そのtableview内でitunesStoreを表示したいのですが、 やり方が分かりませんでした。。 また、画面遷移が行われた場合のitunesStoreの表示はできましたが その場合、ナビゲーションバーの色がデフォルトに戻ってしまい困っております。 以下のやり方を試しましたが、うまくビュー内に表示することができず ご教授いただければと思い質問させていただきました。 よろしくお願い致します。 *---------- .h @interface recVCL : UITableViewController <UIWebViewDelegate> { UIWebView *wv; } @end .m - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSString *compURL = @"http://phobos.apple.com/WebObjects/"; if(NSOrderedSame == [[[request URL] absoluteString] compare:compURL options:NSCaseInsensitiveSearch range:NSMakeRange(0,[compURL length])]) { [[UIApplication sharedApplication] openURL:[request URL]]; } return YES; } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"xxxxxxx"; self.navigationController.navigationBar.tintColor = [[[UIColor alloc] initWithRed:(xxxxxxxxxx) green:(xxxxxxxxxxx) blue:xxxxxxxxxx) alpha:1.0f] autorelease]; wv = [[UIWebView alloc] initWithFrame:self.view.bounds]; [wv delegate]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSURL *url; NSURLRequest *urlRq; switch (indexPath.row) { case 0: url = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=xxxxxxxxxxxx&mt=x"]; urlRq = [NSURLRequest requestWithURL:url]; [wv loadRequest:urlRq]; [self.view addSubview:wv]; break; ... }

  • テーブルビューで配列が自動消滅することについて

    xcode4.1をつかってiphoneアプリを作成しています。 テーブルビューの画面遷移時に、 可変配列NSMutableArrayに plistを読み込ませたNSMutableDictionaryの一意のキーの中身を保存し、 更に選択した行番号で呼び出した配列の中身を別ビューに渡そうとすると失敗してしまいます。 ・・自動解放されてしまっていると思うのですが、 [[[NSMutableArray alloc] init] retain]; としてもうまくいきませんでした。 どうすればうまくデータを別ビューに渡せるでしょうか。 (plistの読み込みは必須です。。) すみませんがご教授いただけますでしょうか。。。 よろしくお願いいたします。 //-------- .h------ @interface DtlVCL : UITableViewController { //別のViewからデータ受け渡し用 NSString *rcvStr; //plist一時読み込み用 NSMutableDictionary *dic; NSMutableArray *ary; } .m------------ viewDidLoad------ //各変数初期化 ary = [[[NSMutableArray alloc] init] retain]; dic = [[[NSMutableDictionary alloc] init] retain]; id path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"xxxxxxxx.plist"]; if([[NSFileManager defaultManager] fileExistsAtPath:path] == YES){ dic = [NSMutableDictionary dictionaryWithContentsOfFile:path]; }else{ NSLog(@"Dtl :ファイル読み込みエラー"); } ary = [dic objectForKey:rcvStr];//rcvStrは前ビューから取得した文字列 ------------------- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath------ ExpVCL *expvcl = [[ExpVCL alloc] initWithNibName:@"ExpVCL" bundle:nil]; //データの受け渡し expvcl.rcvNum = [indexPath row]; expvcl.rcvStr = [NSString stringWithFormat:@"%@",[ary objectAtIndex:[indexPath row]]]; [self.navigationController pushViewController:expvcl animated:YES]; [expvcl release];

  • iphoneアプリ開発での変数の受け渡し

    最近iPhoneアプリ開発を始めた者です。 変数の受け渡しについて質問があり、投稿させていただきました。 以下のコード内で、 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 以下で設定したIDに入ったデータを、 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)senderの中のIDに受け渡したいのですが、どうやら2つのIDが繋がっていません。 自分自身あまりまだ理解できていないこともあり、ざっくりとした聞き方で申し訳ありません。 初歩的な質問だとは思うのですが、なにとぞご教授お願いします。 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } if (indexPath.row == 0){ cell.textLabel.text = @"東京"; }else{ cell.textLabel.text = @"大阪"; } int ID = indexPath.row; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"mySegue" sender:self]; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"mySegue"]) { SecondTableViewController *viewCon = segue.destinationViewController; viewCon.myValue = ID; } }

  • iphoneアプリ開発についての質問です

    http://okwave.jp/qa/q8846564.htmlの質問に補足を付け加えたものです。 storyboardのprototype cellsでカスタムセルを4つ作成しidentifierも設定した状態で、 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static const id identifiers = { @"MetaCell", @"StatusCell", @"EvoCell", @"FormCell" }; NSString *CellIdentifier = identifiers[indexPath.section]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 以下略 という風にしているのですが UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath: というエラーが出てしまいます。 identifierの文字列は何度見ても一致していました。 if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 上記のコードを追加しても、一応エラーは出ませんが当然セルは反映せず真っ白のままです。 if (cell == nil) { if (indexPath.section == 0) { cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; } else if (indexPath.section == 1) { cell = [tableView dequeueReusableCellWithIdentifier:@"StatusCell"]; } else if (indexPath.section == 2) { cell = [tableView dequeueReusableCellWithIdentifier:@"EvoCell"]; } else if (indexPath.section == 3) { cell = [tableView dequeueReusableCellWithIdentifier:@"FormCell"]; } } 一応このようなやりかたでも試しましたが結果は同じでした。 ちなみにこのテーブルビューへは前のビューからsegueで (void)[[segue destinationViewController] initDetailDic:dic]; で遷移してきています。 何度調べても原因がわからず困っています。心当たりはないでしょうか。 *補足 問題の起こっているこのテーブルビューへは、前のテーブルビューから遷移してきているのですが試しにNavigationControllerのrootViewに設定してみたところちゃんと表示されました。画面遷移の方法に原因があると考えられるのですが、上に書いたやり方はごくごく一般の方法だとおもうのですが・・・

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

  • iphoneプログラミング UITableの複数表示

    すいません、基本的なことだとは思うのですが、どうしても分からないため質問させてください。 UITableView を2つ並べてそれぞれに別々の値を入れていきたいのですがどうすればできますか?? - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"MyIdentifer"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; } cell.text = [listOfContents objectAtIndex:indexPath.row]; return cell; } この関数だとUITableの個別の識別ができないため2つとも同じ値が入ってしまいます。