随笔 - 171  文章 - 257  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(33)

随笔分类(225)

随笔档案(171)

相册

技术

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 441507
  • 排名 - 48

最新随笔

最新评论

阅读排行榜

评论排行榜

UITableView 屏蔽了左右滑动事件.  通过重载的方式可以注入事件touch事件, 供开发者使用..

 1 //
 2 //  TouchTableView.h
 3 //  i2fBank4Iphone
 4 //
 5 //  Created by khan.lau on 13-1-8.
 6 //  Copyright (c) 2013年 khan.lau. All rights reserved.
 7 //
 8 
 9 #import <UIKit/UIKit.h>
10 
11 
12 @protocol TouchTableViewDelegate <NSObject>
13 @optional
14 - (void)tableView:(UITableView *)tableView touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event;
15 - (void)tableView:(UITableView *)tableView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
16 - (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
17 - (void)tableView:(UITableView *)tableView touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
18 @end

 1 //
 2 //  TouchTableView.m
 3 //  i2fBank4Iphone
 4 //
 5 //  Created by khan.lau on 13-1-8.
 6 //  Copyright (c) 2013年 khan.lau. All rights reserved.
 7 //
 8 
 9 #import "TouchTableView.h"
10 
11 @implementation TouchTableView
12 
13 @synthesize touchDelegate = _touchDelegate;
14 
15 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
16     [super touchesBegan:touches withEvent:event];
17     
18     if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
19         [_touchDelegate respondsToSelector:@selector(tableView:touchesBegin:withEvent:)])
20     {
21         [_touchDelegate tableView:self touchesBegin:touches withEvent:event];
22     }
23 }
24 
25 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
26     [super touchesCancelled:touches withEvent:event];
27     
28     if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
29         [_touchDelegate respondsToSelector:@selector(tableView:touchesCancelled:withEvent:)])
30     {
31         [_touchDelegate tableView:self touchesCancelled:touches withEvent:event];
32     }
33 }
34 
35 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
36     [super touchesEnded:touches withEvent:event];
37     
38     if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
39         [_touchDelegate respondsToSelector:@selector(tableView:touchesEnded:withEvent:)])
40     {
41         [_touchDelegate tableView:self touchesEnded:touches withEvent:event];
42     }
43 }
44 
45 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
46     [super touchesMoved:touches withEvent:event];
47     
48     if ([_touchDelegate conformsToProtocol:@protocol(TouchTableViewDelegate)] &&
49         [_touchDelegate respondsToSelector:@selector(tableView:touchesMoved:withEvent:)])
50     {
51         [_touchDelegate tableView:self touchesMoved:touches withEvent:event];
52     }
53 }
54 
55 @end
56 


调用方法 :
1. 头文件中加入delegate

@interface MoneyViewCtl : UIViewController<UITableViewDataSource, UITableViewDelegate, SDWebDataDownloaderDelegate, EGORefreshTableHeaderDelegate, TouchTableViewDelegate>{

    

    IBOutlet UISegmentedControl *_sigTime;

    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");

}



剩下的事情就可以自己发挥了


posted on 2013-02-27 02:51 Khan 阅读(5822) 评论(1)  编辑 收藏 引用 所属分类: GCC/G++跨平台开发

FeedBack:
# re: 为UITableView增加左右滑动事件 2015-02-28 09:10 snowking
tableview没有屏蔽右滑事件  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理