Giter Club home page Giter Club logo

yaadaptertableviewwithresponderchain's Introduction

ARTableView.podspec

CI Status Version License Platform

Example

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的事件。 好处:避免了大量的blockdelegate

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;
    
}

Requirements

you need to import"UITableView+adapter"

Installation

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

Author

onlyAngelia, 关门滢

License

ARTableView.podspec is available under the MIT license. See the LICENSE file for more info.

yaadaptertableviewwithresponderchain's People

Contributors

onlyangelia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.