我想将数据存储到 UITable 的 plist 中,但到目前为止,如果它们已经写在那里,我可以从 plist 中读取它们。我想在运行应用程序时写入数据。这是在 UITableView 中将数据保存到单元格的方法
-(IBAction)saveAction:(id)sender
{
Tricks *trick = [[Tricks alloc]init];
trick.trickName = self.trickLabel.text;
//trick.trickPhoto = self.ImagePhoto.image;
[[Tricks trickList]insertObject:trick atIndex:0];
[self.navigationController popViewControllerAnimated:YES];
}
在 detailViewController 中,我可以拍照并在地图上放置图钉。单元格的照片、图钉和文本存储在 NSObject 的子类中。
加载详细视图控制器
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"detailTrick"]){
NSIndexPath *indexPath = nil;
indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
Tricks *trick = [[Tricks trickList] objectAtIndex:indexPath.row];
detailViewController.fileText = trick.trickName;
detailViewController.pinMKPoint = trick.pinNotation;
}
detailViewController.trick = trick;
}
}
连接到 plist 的代码
NSString *trickList = [[NSBundle mainBundle]pathForResource:@"trickList" ofType:@"plist"];
_trick = [[NSMutableDictionary alloc]initWithContentsOfFile:trickList];
_trickPhotos = [[_trick objectForKey:@"trickPhotos"]objectAtIndex:0];
_trickNames = [[_trick objectForKey:@"trickNames"]objectAtIndex:0];
_mapAnnotations = [[_trick objectForKey:@"pinKit"]objectAtIndex:0];
我想在 plist 中写入所有数据并在启动应用程序时读取它们。感谢您的建议。