我一直在嘗試從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