如何跳到detailview中的下一行
我有一个TableView加载在didSelectRow detailview。 我对这些数据没有任何问题。 我正在使用coreData和填充TableView我使用NSFetchedResultsController。
现在,我想在detailView中创build下一个和上一个函数, 以跳转到下一个或上一个表(行)元素 。 下一个上一个像在邮件应用程序。
我知道我必须使用IBAction的button。
但是,我怎样才能使这个function?
谢谢,
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'
如何解决这个问题?
用你的UITableView,你可以通过以下方式获得选定的行:
- (NSIndexPath *)indexPathForSelectedRow
并通过增加indexPath.row来设置select:
- (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]; }
为此,您可以使用DataSource数组进行pipe理。
当你加载你的详细视图的时候,你传递数组的索引(indexPath.row)。 通过该索引,您可以在详细视图中获取数据。 并在该索引中使用递增和递减来获取下一个和前一个单元格的数据。
脚步
1)设置你的tableView。
2)当时redirect到DetailView时,为store当前的indexPath.row设置一个intvariables。 所以在详细视图中定义一个int。
3)使用下一个和上一个buttonpipe理在intvariables中的indexpath.row。 并从Source数组中代表适当的数据。
您可以使用:
(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
获得你想要的单元格(下一个或上一个)。
然后将返回的单元格“Selected”属性设置为YES。
cell.selected = YES