Bli*_*ios 1 objective-c uitableview ios5
我正在开发一个iOS 5应用程序,在我的情况下,如果用户第一次从UITableView点击一行然后它将执行一些操作,如果它被第二次点击,那么它将执行不同的操作.
现在,问题是如何知道特定行是否第二次被点击?
提前致谢!!
那你为什么不在桌面视图中使用UIGestures.这将是最容易解决的问题,对我来说就像魅力一样.
以下代码将帮助您在代码中实现它:
// Put this code in your ViewDidLoad:
UITapGestureRecognizer *doublegesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTableViewCellDoubleTapping:)];
doublegesture.numberOfTapsRequired = 2;
[roomTableView addGestureRecognizer:doublegesture];
[doublegesture release];
Run Code Online (Sandbox Code Playgroud)
//在双击时处理事件的方法
-(void)didTableViewCellDoubleTapping:(UITapGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
CGPoint swipeLocation = [gestureRecognizer locationInView:roomTableView];
NSIndexPath *swipedIndexPath = [roomTableView indexPathForRowAtPoint:swipeLocation];
NSLog(@"%d",swipedIndexPath.row);
// ... Here you can add your logic
}
}
Run Code Online (Sandbox Code Playgroud)
以类似的方式,如果您为单次点击添加另一个UIGesture
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTableViewSingleCellTapping:)];
gesture.numberOfTapsRequired = 1;
[roomTableView addGestureRecognizer:gesture];
[gesture release];
[gesture requireGestureRecognizerToFail:doublegesture];
-(void)didTableViewSingleCellTapping:(UITapGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
CGPoint swipeLocation = [gestureRecognizer locationInView:roomTableView];
NSIndexPath *swipedIndexPath = [roomTableView indexPathForRowAtPoint:swipeLocation];
NSLog(@"%d",swipedIndexPath.row);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
711 次 |
最近记录: |