如何在详细视图中跳转到下一行

2024-02-23

我有一个 TableView,它在 didSelectRow 中加载详细视图。我对数据没有任何问题。 我正在使用 coreData 并使用 NSFetchedResultsController 来填充 TableView。

现在,我想在详细视图中创建下一个和上一个函数跳转到下一个或上一个表(行)元素。下一页 上一页 就像邮件应用程序中一样。
我知道我必须使用 IBAction 按钮。

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

thanks,
brush51

Edit 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];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在详细视图中跳转到下一行 的相关文章

随机推荐