如何在详细视图中跳转到下一行
我有一个 TableView,它在 didSelectRow 中加载详细视图。我对数据没有任何问题。 我正在使用 coreData 并使用 NSFetchedResultsController 来填充 TableView。
现在,我想在详细视图中创建下一个和上一个函数以跳转到下一个或上一个表(行)元素。下一页 上一页 就像邮件应用程序中一样。
我知道我必须使用 IBAction 按钮。
但是我怎样才能实现这个功能?
谢谢,
Brush51
编辑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'
如何解决这个问题?
i have a TableView which loads a detailview in didSelectRow. I have no problems with the data's.
I am using coreData and to populate the TableView i am using a NSFetchedResultsController.
Now, i want to make a next and previous function in the detailView to jump to the next or previous Table(row) Element. Next Previous like in the Mail-App.
I know that i have to use a button with IBAction.
But how can i make this function?
thanks,
brush51
Edit 1:
I have it done so:
- (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
}
But i get an error:
-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0'
How to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 UITableView,您可以通过以下方式获取选定的行:
并通过增加 indexPath.row 来设置选择:
然后您的操作可以是:
With your UITableView, you can get the selected row by:
And set the selection by incrementing the indexPath.row:
then you action could be:
为此,您可以使用 DataSource 数组进行管理。
当您加载详细视图时,您将传递数组索引(indexPath.row)。通过该索引,您可以在详细视图中获取数据。并使用该索引中的增量和减量,您可以获得下一个和上一个单元格的数据。
步骤
1) 设置你的tableView。
2)当重定向到DetailView时,设置一个int变量来存储当前的indexPath.row。所以详细定义一个int View。
3)使用下一个和上一个按钮管理int变量中的indexpath.row。
并表示来自源数组的适当数据。
for that you can manage with your DataSource array.
when you load your detail view at that time you pass your index of array(indexPath.row). by that index you fetch data in detail view. and using increment and decrement in that index you get data for next and previous cell.
Steps
1) setup your tableView.
2) when redirect to DetailView at that time set one int variable for store current indexPath.row . so define one int in detail View.
3) using next and previous button manage indexpath.row which is in int variable.
and represent appropriate data from Source array.
您可以使用:
(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
获取所需的单元格(下一个或上一个)。
然后将返回的单元格“选定”属性设置为“是”。
cell.selected = YES
You can use:
(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
To get the cell you want (next or previous).
And then set the returned cell "Selected" property to YES.
cell.selected = YES