为UITableView增加左右滑动事件
2013-08-14 13:22
375 查看
UITableView 屏蔽了左右滑动事件. 通过重载的方式可以注入事件touch事件, 供开发者使用..
调用方法 :
1. 头文件中加入delegate
2. .m文件中设置好delegate
_tableview.touchDelegate = self;
3. .m文件中实现如下事件
转自:http://www.cppblog.com/Khan/archive/2013/02/27/198100.html
// // TouchTableView.h // #import <UIKit/UIKit.h> @protocol TouchTableViewDelegate <NSObject> @optional - (void)tableView:(UITableView *)tableView touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event; - (void)tableView:(UITableView *)tableView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; - (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)tableView:(UITableView *)tableView touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; @end @interface TouchTableView : UITableView @property(nonatomic,retain) id<TouchTableViewDelegate> touchDelegate; @end
// // TouchTableView.m // #import "TouchTableView.h" @implementation TouchTableView @synthesize touchDelegate = _touchDelegate; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] && [_touchDelegate respondsToSelector:@selector(tableView:touchesBegin:withEvent:)]) { [_touchDelegate tableView:self touchesBegin:touches withEvent:event]; } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] && [_touchDelegate respondsToSelector:@selector(tableView:touchesCancelled:withEvent:)]) { [_touchDelegate tableView:self touchesCancelled:touches withEvent:event]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] && [_touchDelegate respondsToSelector:@selector(tableView:touchesEnded:withEvent:)]) { [_touchDelegate tableView:self touchesEnded:touches withEvent:event]; } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] && [_touchDelegate respondsToSelector:@selector(tableView:touchesMoved:withEvent:)]) { [_touchDelegate tableView:self touchesMoved:touches withEvent:event]; } } @end
调用方法 :
1. 头文件中加入delegate
@interface MoneyViewCtl : UIViewController<UITableViewDataSource, UITableViewDelegate, TouchTableViewDelegate> { IBOutlet TouchTableView *_tableview; } @end
2. .m文件中设置好delegate
_tableview.touchDelegate = self;
3. .m文件中实现如下事件
#pragma mark - TouchTableViewDelegate lifecycle - (void)tableView:(UITableView *)tableView touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesBegin"); } - (void)tableView:(UITableView *)tableView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesCancelled"); } - (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesEnded"); } - (void)tableView:(UITableView *)tableView touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesMoved"); }剩下的事情就可以自己发挥了
转自:http://www.cppblog.com/Khan/archive/2013/02/27/198100.html
相关文章推荐
- 为UITableView增加左右滑动事件
- 为嵌套在左右滑动的UIScrollview上的UITableView增加滑动删除
- 为嵌套在左右滑动的UIScrollview上的UITableView增加滑动删除
- 【Android】ViewPager实现图片左右滑动播放及添加点击事件
- 009、使用ViewFlipper实现左右滑动事件
- 禁止ViewPager左右滑动事件
- UITableView 左右滑动时,出现删除按钮的动画(可自定义)。
- android 事件拦截 (Viewpager不可以左右滑动)
- 禁止ViewPager的左右滑动事件
- 通过onTouch事件左右滑动view
- iOS使用UIScrollView实现左右滑动UITableView和UICollectionView
- Android-ViewPager-禁用左右滑动事件
- ViewFlipper左右滑动事件
- 解决viewpager与其他可以左右滑动的事件冲突
- iOS开发-UITableView-3(左右滑动)
- Android开发:监听当前View的左右滑动事件,并返回给当前的activity或者fragment
- UITableView中识别左右滑动,实现上下翻页的功能
- UITableView增加自定义Button并绑定点击事件
- 解决ViewPager的左右滑动和点击返回事件的冲突
- iOS UITableView实现滑动删除、增加、多选