P.J*_*P.J 19 iphone objective-c uitableview ios swipe-gesture
我正在进行滑动手势UITableView
并且想知道我的手指当前进入的单元格的索引路径,即从哪个单元格执行的滑动手势.
我需要indexPath
显示所选单元格的信息.
提前致谢..
Sri*_*aju 53
那么你基本上需要的是从桌面上轻扫手势获取单元格?对indexPath
.你不需要知道.首先定义滑动tableView
等 -
UISwipeGestureRecognizer *showExtrasSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwipe:)];
showExtrasSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[tableView addGestureRecognizer:showExtrasSwipe];
[showExtrasSwipe release];
Run Code Online (Sandbox Code Playgroud)
在此之后,当实际滑动发生时,您需要将处理程序放入其中.为此尝试这个 -
-(void)cellSwipe:(UISwipeGestureRecognizer *)gesture
{
CGPoint location = [gesture locationInView:tableView];
NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location];
UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath];
//Your own code...
}
Run Code Online (Sandbox Code Playgroud)
所以,我们所做的是第一次附加SwipeGestureRecognizer
的UITableView
(不是UITableViewCell
).之后,当滑动发生时UITableView
,我首先得到手势发生在哪里的坐标UITableView
.接下来,使用这个坐标,我得到了IndexPath
滑动发生的行UITableView
.最后使用IndexPath
我得到了UITableViewCell
.真的很简单..
注意:我被问过这么多次.所以加入的,为什么我用这个解释SwipeGestureRecognizer
的UITableView
,而不是每一个人 UITableViewCell
.
我可以依附于SwipeGestureRecognizer
每个人UITableViewCell
.我没有这样做,因为我不得不SwipeGestureRecognizer
为每个细胞附加一个单独的.所以,如果我有1000个单元格,我UITableView
将不得不创建1000个SwipeGestureRecognizer
对象.这个不好.在我的上述方法中,我只创建了一个SwipeGestureRecognizer
,就是这样.
归档时间: |
|
查看次数: |
13049 次 |
最近记录: |