学习官方文档(photoLocations)
2014-04-08 22:01
253 查看
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; APLEvent *event = (self.eventsArray)[indexPath.row]; APLEventDetailViewController *inspector = (APLEventDetailViewController *)[segue destinationViewController]; inspector.event = event; }
这里用了storyboard的destionViewcontroller(segue),可以将storyboard中连线的下一个目标viewcontroller在代码中添加跳转信息。这里为每行的跳转even都分开定义好,因此可以做到在storyboard中一个跳转页面但能实现创建多个。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the managed object at the given index path. NSManagedObject *eventToDelete = (self.eventsArray)[indexPath.row]; [self.managedObjectContext deleteObject:eventToDelete]; // Update the array and table view. [self.eventsArray removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:YES]; // Commit the change. NSError *error = nil; if (![self.managedObjectContext save:&error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } }这是删除选中row的代码,分为在tableview中删除,和在数据中删除;
这里的@[indexPath] 把后者转换成(NSArray *)类型;
刚开始不是很明白,问了才知道,原来这是数组的初始化。是ios6之后引入的方式。mark下。
@[] 初始化不可变数组
@{} 初始化不可变字典
- (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.leftBarButtonItem = self.editButtonItem; // Start the location manager. [[self locationManager] startUpdatingLocation]; /* Fetch existing events. Create a fetch request, add a sort descriptor, then execute the fetch. */ NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; // Order the events by creation date, most recent first. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:NO]; [request setSortDescriptors:@[sortDescriptor]]; // Execute the fetch -- create a mutable copy of the result. NSError *error = nil; NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResults == nil) { // Handle the error. } // Set self's events array to the mutable array, then clean up. [self setEventsArray:mutableFetchResults]; }具体的codedata实现~
相关文章推荐
- tensorflow学习笔记十七:tensorflow官方文档学习 Convolutional Neural Networks
- Spring 4 官方文档学习(⑦)Web MVC 框架之HTTP caching support
- Jersey 2.22.2 官方文档第18章学习笔记
- ios学习之苹果官方文档的学习(按钮点击事件方面)
- Structured Streaming Programming Guide官方文档再次阅读理解强化学习
- javafx官方文档学习之一Application与Stage,Scene初探
- MyBatis 官方文档学习3---XML 映射配置文件
- Spring 4 官方文档学习(六)核心技术之Spring AOP
- NFC官方文档学习笔记(一):NFC前台调度
- ES权威指南[官方文档学习笔记]-33 Updating a whole document
- ES权威指南[官方文档学习笔记]-17 Tutorial Conclusion
- ES权威指南[官方文档学习笔记]-55 Exact values vs. Full text
- Spring Boot 官方文档学习(二)特点
- Spring官方文档学习(3.2)
- gcc之ld 官方文档学习
- Android Geofence的学习(一)翻译官方文档
- Jersey 2.22.2 官方文档第7章学习笔记
- u3d_插件DoTween:(12)学习DoTween的官方文档
- 2017.4.10 spring-ldap官方文档学习
- Spring 4 官方文档学习(十一)Web MVC 框架之multipart(文件上传)支持