我一直在尝试从plist文件中读取数据。这是它的结构需要帮助阅读目标文件中的plist文件c
|term|detail(string)|
我的属性:
@property (nonatomic, strong) NSDictionary *terms;
@property (nonatomic, strong) NSArray *termKeys;//this is just a array to keep track
@property (nonatomic, strong) NSString *detail;
这是我访问详细的的cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSString *currentTermsName = [termKeys objectAtIndex :[indexPath row]];
[[cell textLabel] setText:currentTermsName];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
detail = [terms objectForKey:[termKeys objectAtIndex:indexPath.row]];
NSLog(@" bombs %@",terms[@"Bomb Threats"]);
return cell;
}
,并鉴于didload我
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile = [[NSBundle mainBundle]
pathForResource:@"terms" ofType:@"plist"];
terms = [[NSDictionary alloc] initWithContentsOfFile:myfile];
termKeys = [terms allKeys];
}
它acc esses的值,但它存储每个对象相同的一个 可以说我有5个不同的记录plist,如果我打印的细节它显示相同的记录5次。
Once detail is set then I pass it to detialView
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"detailsegue"]){
TermsDetailViewController *controller = (TermsDetailViewController *)segue.destinationViewController;
controller.detailTerm = detail;
}
}
这里是我的字典: http://pastebin.com/bxAjJzHp
你是什么意思“,它存储相同的一个为每个对象“? – nielsbot 2013-03-04 02:04:15
可以说我有5个不同的记录plist,如果我打印'detail'它显示相同的记录5次 – meda 2013-03-04 02:13:28
我想你应该使用这个:'detail = [[terms objectForKey:@“termKeys objectAtIndex:indexPath.row]] objectForKey:@“detail”]' – nielsbot 2013-03-04 03:25:57