![イメージ説明]WIDTH:600
xcode 6.0.1 でobjective-cを使い辞書アプリを製作しています。
内容はplistのkey"title"をテーブルビューのセルに貼り付けて、選択するとkey"contents"の文字を画面遷移先に表示するアプリです。
前回、teratailでご助言いただき、plistから特定のkey<title>を取得してセルに並べる事が出来ました。ありがとうございます。
しかし、key<title>を選択して遷移した先のviewcontrollerにkey<title>と同じアイテムの中にあるkey<contents>を表示したいのですが、どのようなコードをtableviewやviewcontollerのファイルに追加すればよいでしょうか?
下記の参考にしているページではplistに含まれている画像の名前から画像を遷移先に表示するのですが、自分では応用できませんでした。
質問ばかりで大変恐縮ですが、ご助言お願い致します。
参考:https://akira-watson.com/iphone/tableview_3_objective-c.html
————PropertyList.plist——————————————————————————
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">
<array>
<dict>
<key>title</key>
<string>核</string>
<key>contents</key>
<string>DNAを含有する</string>
</dict>
<dict>
<key>title</key>
<string>ミトコンドリア</string>
<key>contents</key>
<string>ATPを作る</string>
</dict>
<dict>
<key>title</key>
<string>ゴルジ体</string>
<key>contents</key>
<string>分泌に関与</string>
</dict>
<dict>
<key>title</key>
<string>葉緑体</string>
<key>contents</key>
<string>光合成を行う</string>
</dict>
<dict>
<key>title</key>
<string>液胞</string>
<key>contents</key>
<string>アントシアニンを含み浸透圧調節機能を持つ</string>
</dict>
</array>
</plist>
———————————————————————————————————————-
————TableViewController.h—————————————————
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
@end
————————————————————————————————————————
————TableViewController.m—————————————————
#import "TableViewController.h"
@interface TableViewController (){
NSArray* arrayList;
}
@end
@implementation TableViewController
(void)viewDidLoad
{
[super viewDidLoad];
//plistのパスを取得してarrayの配列に入れる
NSString* dataFile = [[NSBundle mainBundle]pathForResource:@"PropertyList" ofType:@"plist"];
arrayList = [NSArray arrayWithContentsOfFile:dataFile];
}
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// セクションの数を1個にしました
return 1;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// 行数を10にしました
return 10;
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *listDict = [arrayList objectAtIndex:indexPath.row];
cell.textLabel.text = [listDict objectForKey:@"title"];
cell.textLabel.textColor = [UIColor cyanColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.detailTextLabel.textColor = [UIColor lightGrayColor];
return cell;
}
// セルの背景色を変える
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
}
@end
——————————————————————————————————————
――――――ViewController.h――――――――――――――――――――――――
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
――――――――――――――――――――――――――――――――――――――
――――――ViewController.m――――――――――――――――――――――――
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
――――――――――――――――――――――――――――――――――――――
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。