学习官方文档(photoLocations)
来源:互联网 发布:mysql安装配置 编辑:程序博客网 时间:2024/04/27 16:59
-(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实现~ 0 0
- 学习官方文档(photoLocations)
- Spring官方文档学习(0)
- Spring官方文档学习(1)
- Spring官方文档学习(2)
- Spring官方文档学习(3)
- Spring官方文档学习(3.1)
- Spring官方文档学习(3.2)
- 跟着angularjs2官方文档学习(一)
- 跟着angularjs2官方文档学习(二)
- 跟着angularjs2官方文档学习(三)
- 跟着angularjs2官方文档学习(四)
- 跟着angularjs2官方文档学习(五)
- ProGaurd官方文档学习笔记(一)
- ProGaurd官方文档学习笔记(二)
- Solidity官方文档学习笔记(2)
- oracle官方文档学习
- Android官方文档学习
- golang官方学习文档
- 前序 开始写博客
- 讲故事学设计模式-状态(State)模式
- C++ map的基本操作和使用
- SQLite数据库的增删改查
- 学习Java第一个类--Object
- 学习官方文档(photoLocations)
- uva 690 - Pipeline Scheduling(dfs+剪枝)
- UVaOJ_489 - Hangman Judge
- phonegap + xcode5.0.2 配置开发环境
- nyoj119
- 深入理解C++的动态绑定和静态绑定
- 关于惠普的增霸卡
- kaldi主页上的翻译的事情(更新)
- input文本框和验证码对齐问题解决