![イメージ説明]WIDTH:600
xcode 6.0.1 でobjective-cを使い辞書アプリを製作しています。
内容はplistのkey"title"をテーブルビューのセルに貼り付けて、選択するとkey"contents"の文字を画面遷移先に表示するアプリです。
plistのpathを取得する方法は調べてわかったのですが、その後の、特定のkeyをセルに表示する方法がどうしてもうまくいかないので、ご助言をお願いいたします。
参考:https://akira-watson.com/iphone/tableview_2.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
——————————————————————————————————————
至らぬ点があるとは思いますが、ご回答をお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。