ios - 如何在detailview中跳转到下一行

标签 ios uitableview core-data row nsfetchedresultscontroller

我有一个 TableView,它在 didSelectRow 中加载了一个详细 View 。我对数据没有问题。 我正在使用 coreData 并填充我正在使用 NSFetchedResultsController 的 TableView。

现在,我想在 detailView 中创建一个 next 和 previous 函数以跳转到下一个或上一个 Table(行)元素。 Next Previous 就像在 Mail-App 中一样。
我知道我必须使用带有 IBAction 的按钮。

但是我怎样才能实现这个功能呢?

谢谢,
刷51

编辑 1: 我这样做了:

- (IBAction) previousCard:(id) sender {  
    NSLog(@"previousBtn");

DashboardViewController *parent = (DashboardViewController *)self.parentViewController;

NSIndexPath *actualIndexPath = selectedRow2;
NSIndexPath * newIndexPath = [NSIndexPath  indexPathForRow:actualIndexPath.row-1 inSection:actualIndexPath.section];
NSLog(@"newIndexPath: %@", newIndexPath);
[parent.tableViews selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; //HERE I GET SIGABRT

}

但是我得到一个错误:

-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0'  

如何解决?

最佳答案

使用 UITableView,您可以通过以下方式获取选定的行:

- (NSIndexPath *)indexPathForSelectedRow

并通过递增 indexPath.row 来设置选择:

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition

那么你的行动可能是:

-(IBAction)nextCell:(id)sender {
  NSIndexPath * actualIndexPath = myTableView.indexPathForSelectedRow;
  NSIndexPath * newIndexPath = [NSIndexPath  indexPathForRow:actualIndexPath.row+1 inSection:actualIndexPath.section];
  [myTableView selectRowAtIndexPath:newIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}

关于ios - 如何在detailview中跳转到下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7874524/

相关文章:

ios - 设置 UIProgressView 进度时不需要的高度约束动画

objective-c - 如何获取数组中 ipodLibrary 中所有歌曲的列表

ios - "The app' s Info.plist 必须包含 NSPhotoLibraryAddUsageDescription 的崩溃是什么?

ios - 如何使 UITableViewCell 的动态高度

ios - MagicalRecord:修改相关对象的属性

ios - 在iOS中以逗号开头和结尾的字符串

ios - 应用程序由于未捕获的异常“NSRangeException”而终止

ios - 如何告诉 UITableView 自调整单元格的高度即将改变?

ios - Swift、GCD 和 CoreData 错误 : error: NULL _cd_rawData but the object is not being turned into a fault

ios - 从核心数据中获取独特值(value)