アコーディオン風のtableviewの遷移について

このQ&Aのポイント
  • アコーディオン風の階層的なtableviewからタップで画面を遷移するコードを作成中です。
  • セルにAとBがでてきて、AをタップするとA⇨Item1,Item2,Item3,BをタップするとB⇨Item1,Item2,Item3というようにそれぞれのセルがでてくるようにしています。
  • 次にItemのセルをタップすると、そのタップしたItemに相当する番号に合わせて画面が遷移するようにしたいですが、その方法がわかりません。
回答を見る
  • ベストアンサー

アコーディオン風のtableviewの遷移について

現在、アコーディオン風の階層的なtableviewからタップで画面を遷移するコードを作っています。 一番最初にでてくる画面のセルにAとBがでてきて、AをタップするとA⇨Item1,Item2,Item3,Bをタップすると B⇨Item1,Item2,Item3というように各々セルがでてくるようにしています。その際、コードはdidSelectRowAtIndexPathメソッドに書いてあります。 そこで、次にItemのセルをタップすると、そのタップしたItemに相当する番号(プロパティリストを読み込む)に合わせて画面が遷移するようにしたいのですが、その方法がわかりません。 (didSelectRowAtIndexPathのところに書くと、セルのAやBをタップした時点で画面が遷移してしまい、Itemのセルがでてこないです。) 色々試してはいるのですが、どのように書いたらいいか、わからなくています。 もし、宜しければ、お手数おかけしますがご教授頂けたら幸いです。 以下、コードです。 Xcodeは5.0を使用しています。 @property (nonatomic, retain) NSArray *arrayOriginal; @property (nonatomic, retain) NSMutableArray *arForTable; //ここで、プロパティリストを読み込んでいます。 NSDictionary *dTmp=[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data1" ofType:@"plist"]]; self.arrayOriginal=[dTmp valueForKey:@"Objects"]; self.arForTable=[[NSMutableArray alloc] init] ; [self.arForTable addObjectsFromArray:self.arrayOriginal]; - (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] ; } cell.textLabel.text=[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"name"]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row]; if([d valueForKey:@"Objects"]) { NSArray *ar=[d valueForKey:@"Objects"]; BOOL isAlreadyInserted=NO; for(NSDictionary *dInner in ar ){ NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner]; isAlreadyInserted=(index>0 && index!=NSIntegerMax); if(isAlreadyInserted) break; } if(isAlreadyInserted) { //miniMizeThisRowでAやBが閉じるようにしています。 [self miniMizeThisRows:ar]; } else { NSUInteger count=indexPath.row+1; NSMutableArray *arCells=[NSMutableArray array]; for(NSDictionary *dInner in ar ) { [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]]; [self.arForTable insertObject:dInner atIndex:count++]; } //ここでAやBが開いて相当するItemがでるようにしています。 [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationFade]; } } //閉まる際のメソッドです。 -(void)miniMizeThisRows:(NSArray*)ar{ for(NSDictionary *dInner in ar ) { NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner]; NSArray *arInner=[dInner valueForKey:@"Objects"]; if(arInner && [arInner count]>0){ [self miniMizeThisRows:arInner]; } if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) { [self.arForTable removeObjectIdenticalTo:dInner]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: [NSIndexPath indexPathForRow:indexToRemove inSection:0] ] withRowAnimation:UITableViewRowAnimationFade]; }}} プロパティリストです。 <dict> <key>Objects</key> <array> <dict> <key>name</key> <string>A</string> <key>level</key> <integer>0</integer> <key>Objects</key> <array> <dict> <key>name</key> <string>Item1</string> <key>level</key> <integer>3</integer> </dict> <dict> <key>name</key> <string>Item2</string> <key>level</key> <integer>1</integer> </dict> <dict> <key>name</key> <string>Item3</string> <key>level</key> <integer>1</integer> </dict> </array> </dict> <dict> <key>name</key> <string>B</string> <key>level</key> <string></string> <key>Objects</key> <array> <dict> <key>name</key> <string>Item1</string> <key>level</key> <integer>0</integer> </dict> <dict> お手数おかけしまして恐縮ですが、宜しくお願い致します。

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

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

didSelectRowAtIndexPathの先頭付近に if([d valueForKey:@"Objects"]) { というif文がありまよね。 ここは、dというテーブル選択位置のNSDictionaryオブジェクトの中に "Objects"というキーがあるかを確認しており、それが存在する場合を アコーディオン伸長/縮小処理が必要な項目のタップだと判断しているようです。 つまり、このif文のelseルート(すなわち"Objects"というキーがないケース)が アコーディオン伸長/縮小処理が不要な最下位層の項目を選択したということになります。 とりあえず、このif文のelseルートを作り、そこに NSLog(@"Select %@",[d valueForKey:@"name"]); とか書けば、Itemのセルをタップした時にログが表示されると思います。

niconico7chan
質問者

お礼

Lchan0211bさん、本当に本当、いつも助けて頂きましてありがとうございます!(涙) お陰さまで、教えて頂いたとおりに、elseルートを作り遷移させると、2行のコードの追加で 遷移することができました。 また、これまで教えて頂きました、PageViewやViewControllerの画面にもplistに相関させている数字で画像を乗せることができました。 本当に、いつもお時間を割いて頂き、どれだけ助けて頂いたかと思うと感謝尽せません。 本当にありがとうございました。

その他の回答 (1)

noname#190876
noname#190876
回答No.2

聞いてることと、やってることのギャップがひどいですが。 これは、Collapsible TableViewといって、高等トピックですが、聞いているのは、かなり初級なことです。 テーブルの中身を、plistからよびだすとこなんかも、通らしさがでてますので、おそらく、どこかからパクってきたけど 中身が、わかりきってないのでは。  Collapsible TableView については、WWDC-2013のサンプルコードのなかに、いいやつがあります。  拾い方は、wwdc-downloader で、ググれ。英語優先で引いたほうがいいだろう。  さて、cell-1,cell-2,cell-3 で、画面推移したく、cell-A,cell-Bで、画面推移したくないなら、 A)cell-1,cell-2,cell-3で、対応するアクションwp定義しておく。cell-A,cell-Bで、アクションを定義しない。 B)cell-1,cell-2,cell-3,cell-A,cell-Bを区別せず、UITableVuewDelegateのdidSelect...で、分別処理する。  のどちらかになりますが、あきらかに、A案の方が上策だと思いますけどね。問題は、addTargetできるのは、UIControlの子孫だけなので、UIButtonの類をおくか、全面に、みえないUIBottonを配置するというのは、どう。

niconico7chan
質問者

お礼

いつもありがとうございます。(以前のTag番号のところではお世話になりました!) xpd154さんのご指摘通りです。 全くのゼロから独学でやってまして、全くわからず、色々な方のgithubなどを参考にさせて頂き作業を進めておりまして、伺っている内容とのギャップがでてしまい、申し訳ない質問の内容になっております。すみません。 wwdc-downloaderというのは全く存じておりませんでした。 ありがとうございます。 お陰さまでA案に近いやり方でできるようになりました。 貴重な時間を割いて頂き、貴重なアドバイスをありがとうございました。

関連するQ&A

  • 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 と順番が逆になってしまうのです。 全く理由がわかりません。ぜひとも回答の方をお願い致します。 初めての投稿ですので、どのように説明していけばいいのかわかりませんでした。 ですが、どうしても直したい問題ですので、よろしくお願い致します。

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

    XCodeでUISearchBarをUITableViewヘッダーにおいてテーブルビューの要素を検索したいのですがエラーになります。 サイズがテキスト量によって可変するカスタムセルをStoryboardで作れないのでコードで作成したんですが、その場合だとサーチバーにテキストを入力し検索を押した時点でエラーになり *** Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], となってしまいます。 セル生成のコードは以下になります - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //ココでエラー NSDictionary *dic; if (tableView == self.searchDisplayController.searchResultsTableView) { dic = self.searchResult[indexPath.row]; } else { dic = self.itemArr[indexPath.row]; } cell.title.text = dic[@"title"]; cell.label.text = dic[@"detail"]; CGSize textSize = [dic[@"detail"] sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(300, 200) lineBreakMode:NSLineBreakByWordWrapping]; cell.label.frame = CGRectMake(10, 35, textSize.width, textSize.height); return cell; } Storyboard上のprototypecellなら問題なく動作するのですが、どうしてもコード生成のカスタムセルだとエラーになってしまうようです。 アドバイスお願いします。

  • TableViewでセル名が表示されない

    こんにちは。 iPhoneアプリの勉強している者ですが、TableViewControllerを使いセルごとに名前を表示させようとしているのですが、タイトルのみが表示されて肝心のセル名が表示されません。 appDelegate.mにてUINavigationControllerのインスタンス及びUITableViewControllerのインスタンスを作成してUITableViewControllerのインスタンスをrootViewControllerに設定しTableViewを表示させようとしています。 プログラムの記述のどこが間違っているのか教えて頂けると大変助かります。 以下UITableViewControllerのinterfaceセクションとimplementationセクションを掲載しますので、ご指摘お願いします。 #import <UIKit/UIKit.h> @interface SampleForSimpleTable : UITableViewController { NSArray *itemes; } @end @implementation SampleForSimpleTable - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"SimpleTable"; itemes = [[NSArray alloc] initWithObjects:@"ITME 1", @"ITEM 2", @"ITEM 3", @"ITEM 4", @"ITEM 5", @"ITEM 6", nil]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation. // Return the number of sections. return 0; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete method implementation. // Return the number of rows in the section. return [itemes count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"default-cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier ]; if (!cell){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.textLabel.text = [itemes objectAtIndex:indexPath.row]; // Configure the cell... return cell; }

  • 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つとも同じ値が入ってしまいます。

  • 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というエラーが吐き出されていました。 同様のエラーが出た例などを調べてみたのですが自力では解決できず・・・、どなたか原因を指摘して頂けるとありがたいです。 よろしくお願いします。

  • iphoneでTableViewに動的追加できない

    UITableViewでWebから取得した情報を表示したく、非同期にCellを追加する テストアプリを書いていたのですが、わからない点がいくつかあります。 以下は非同期追加のテストコードで、実行するとリストに"foo"が一件だけ表示され 2秒おきにリストに”bar”が追加されます。 @interface AddRowTableViewController : UITableViewController { NSMutableArray *dataSouce; } -(void)onTimer:(NSTimer*)timer; @end @implementation AddRowTableViewController - (void)viewDidLoad { // 初期値は空欄 dataSouce = [[NSMutableArray alloc] init]; // (1) // 初期値としてfooを持つ //dataSouce = [[NSMutableArray alloc] initWithObjects:@"foo", nil]; // (1)' // 2秒ごとにbarを追加するためにインターバルタイマをセット [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(onTimer:) userInfo:nil repeats:YES]; } // 2秒ごとに挿入のために呼ばれる -(void)onTimer:(NSTimer*)timer { // barを追加 [dataSouce addObject:@"bar"]; [self.tableView beginUpdates]; NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0]; // (2) [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:UITableViewRowAnimationTop]; [self.tableView endUpdates]; // (3) [self.tableView reloadData]; // (4) } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [dataSouce count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *id = @"default-cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id]; if(!cell){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:id]; [cell autorelease]; } cell.textLabel.text = [dataSouce objectAtIndex:indexPath.row]; return cell; } #if 0 // (5) - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if([dataSouce count] > 0) return 1; else return 0; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // テストなので、聞かれたらTitleと答えておく return @"title"; } #endif @end このプログラムは一応動作するのですが、少し変えると期待通りに動作しません。 疑問1 コード中の(1)をコメントアウト及び(1)’をコメントインした状態で、初期値として "foo"が画面に表示された状態からスタートするようになりますが、このとき (2)で先頭に挿入するように記載していますが、実際には2行目に挿入されます。 foo bar bar 例えば4秒後にはこんな感じに並びます。なぜでしょうか? 疑問2 (4)のコードを書くと挿入時にアニメーションしません。(4)のコードを書かないとbarではなく fooが追加されたように見えます。スクロールしてフレームアウト/インなどの動作が あるとセルがリロードされ正しくbarになります。 挿入アニメーションを有効にしつつ最新データを参照させるにはどうしたらよいのでしょうか? 疑問3 (5)を#if 1とすることでセクションが表示されるようになりますが、このときに 初期値として何かあれば追加できますが、初期状態が空欄の場合に追加できず (3)のコードがSIGABRTを発行してしまいます((1)だとNG、(1)’だと通る)。 空欄のセクション付きリストにCellを挿入するにはどうしたらよいでしょうか? 経験が浅く、非常識なコードになっているのではないかと思いますが、 どうにも自力ではこれ以上進めなくなってしまいました。 上記1~3の一つでもいいので、なにかヒントをいただけないでしょうか? 未検証のカンによるアドバイスも歓迎です、こちらで検証させて頂きます。 どうかよろしくお願い致します。

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

  • カスタムセル内のLabelの値の取り出し

    iOSアプリ開発において解決できない課題が出てきたので、なにかご助言をいただけるとありがたいです。 やりたいことは、TableViewにおいて、タップされたカスタムセル内のラベルの値を取り出す、ということです。 ネット上にこのやり方について説明したページはいくつもあり、その通りに実装してみたのですがうまくいきません。 コードの該当箇所は以下です。 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; // カスタムセルにキャスト。キャストすることによりカスタムセルのpropertyが使える CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSLog(@"%@",cell.label.text); } ビルドしてセルをタップすると、どのセルであってもlabelの初期値である"Label"としか出力されないです。 シミュレータでのセルの表示自体は問題ないです。 なにか原因として考えられることがあれば指摘していただけるとありがたいです。 どうかよろしくお願いします。

  • Objecive-C

    NSDictionary *row1 = [[NSDictionary alloc]initWithObjectsAndKeys:            @"MacBook",@"Name",@"White",@"Color",nil]; NSDictionary *row2 = [[NSDictionary alloc]initWithObjectsAndKeys:        @"MacPro",@"Name",@"Silver",@"Color",nil]; NSArray *array● = [[NSArray alloc]initWithObjects:row1,row2,nil]; これをplistを使って実現させようと思ったのですが、 NSString *path =[[NSBundle mainBundle]pathForResource:@"Celldata" ofType:@"plist"]; NSArray *array○ = [[NSArray alloc]initWithContentsOfFile:path]; *array●と*array○は同様の配列で実現可能ですか? plistに問題があるのでしょうか?。 plistは、下記です。 key Type Value Root Dictionary row1 Dictionary ( 2 items) Name String MacBooc Color String White

専門家に質問してみよう