bru*_*h51 3 row core-data uitableview nsfetchedresultscontroller ios
我有一个TableView,它在didSelectRow中加载了一个detailview.我对数据没有任何问题.我正在使用coreData并填充TableView我正在使用NSFetchedResultsController.
现在,我想在detailView中创建next和previous函数以跳转到下一个或上一个Table(row)元素.像Mail-App中的Next Previous.
我知道我必须使用带有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
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误:
-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableViews]: unrecognized selector sent to instance 0xd758ae0'
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?
Ben*_*oît 10
使用UITableView,您可以通过以下方式获取所选行:
- (NSIndexPath *)indexPathForSelectedRow
Run Code Online (Sandbox Code Playgroud)
并通过递增indexPath.row来设置选择:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
Run Code Online (Sandbox Code Playgroud)
然后你的行动可能是:
-(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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3633 次 |
| 最近记录: |