1.create an adapter extends UITableViewAdapter,overwrite the delegate that you will use
2.Then setting UITableView
[_tableView setAdapter:[self adapter]]
3.Next overwriting the func in tableView's superclass
- (void)rountEvent:(NSString *)eventName userInfo:(NSDictionary *)userInfo
4.Last create NSInvocation according to eventName
- (void)rountEvent:(NSString *)eventName userInfo:(NSDictionary *)userInfo
{
NSInvocation *invocation = [self strategyDictionary][eventName];
[invocation setArgument:&userInfo atIndex:2];
[invocation invoke];
}
- (NSDictionary *)strategyDictionary{
NSDictionary *strategyDictionary = @{kCCellSeletedEventName:[self createInvocationWithSeletor:@selector(jumpToController:)]};
return strategyDictionary;
}
1.创建一个adapter 继承自UITableViewAdapter,在新创建的adapter中重写可能会用到的类 2.设置tableView和adapter关联一起
[_tableView setAdapter:[self adapter]]
3.接收tableView的点击事件以及滑动事件,因这里是基于ResponderChain传递,所以只要在tableview的super中实现
- (void)rountEvent:(NSString *)eventName userInfo:(NSDictionary *)userInfo
该方法即可监听tableView的事件。
好处:避免了大量的block
和delegate
4.采用strategy模式避免n多if-else
每个点击事件最终要执行不同的@selector
,所以我们可以采用策略模式,直接取消[self performSelector:<#(nonnull SEL)#> withObject:<#(nullable id)#>]
将@selector
定义为更深一层NSInvocation
,用NSDictionary存储
- (void)rountEvent:(NSString *)eventName userInfo:(NSDictionary *)userInfo
{
NSInvocation *invocation = [self strategyDictionary][eventName];
[invocation setArgument:&userInfo atIndex:2];
[invocation invoke];
}
- (NSDictionary *)strategyDictionary{
NSDictionary *strategyDictionary = @{kCCellSeletedEventName:[self createInvocationWithSeletor:@selector(jumpToController:)]};
return strategyDictionary;
}
you need to import"UITableView+adapter"
ARTableView.podspec is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ARTableView', '~> 1.0.2'
Then run a pod install inside your terminal
onlyAngelia, 关门滢
ARTableView.podspec is available under the MIT license. See the LICENSE file for more info.