objective-cでplistの内容をtableviewに表示させる
Posted: 2013年8月24日(土) 01:10
objective-cでplistの内容をtableviewに表示させたいのですが表示されません。
辞書を作ろうと思っていてtableにPlistにあるアルファベットを表示させたいです。(今回はAとBのみだが辞書なのでZまで作る予定です)
以下のソースが自分で調べたり考えたりして作ってみた物ですがtableは表示されますが文字は表示されません。
ご教授願います。
Xcode4.6.3です。
[word.plist]
[.h]
[.m]
辞書を作ろうと思っていてtableにPlistにあるアルファベットを表示させたいです。(今回はAとBのみだが辞書なのでZまで作る予定です)
以下のソースが自分で調べたり考えたりして作ってみた物ですがtableは表示されますが文字は表示されません。
ご教授願います。
Xcode4.6.3です。
[word.plist]
<plist version="1.0">
<array>
<dict>
<key>英語</key>
<string>A</string>
<key>意味</key>
<string>アルファベットのA</string>
</dict>
<dict>
<key>英語</key>
<string>B</string>
<key>意味</key>
<string>アルファベットのB</string>
</dict>
</array>
</plist>
@interface TableViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> {
__weak IBOutlet UITableView *word_table;
NSArray *word_data;
NSDictionary *allData;
}
@property (nonatomic, retain) NSDictionary *allData;
@property (nonatomic, retain) NSArray *word_data;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:@"word" ofType:@"plist"];
word_data = [NSArray arrayWithContentsOfFile:path];
word_table.dataSource = self;
word_table.delegate = self;
word_table.backgroundColor = [UIColor blueColor];
word_table.rowHeight =30;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [allData count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *data = [allData allValues];
return [[data objectAtIndex:section]count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:
(NSInteger)section{
NSArray *dataTitle = [allData allKeys];
return [dataTitle objectAtIndex:section];
}
- (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 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont systemFontOfSize:40];
cell.textLabel.text = [word_data objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.text=@"辞書";
cell.detailTextLabel.textColor=[UIColor whiteColor];
}
return cell;
}