41

TableView弹窗 弹性设置,一行代码接入

 5 years ago
source link: http://www.cocoachina.com/ios/20180926/25020.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在上一篇文章中,提到了封装弹窗控制器,刚好项目中用到了弹窗tableView列表,所以趁热打铁,也就拿过来了。先看看项目效果:

FjayIrF.png!web

HLPopTabView.gif

主要的设计思路和上篇文章的一样,不过是将弹出的view设置成tableView,cell的点击事件通过block回调。

使用方法

  1. 倒入头文件,之际创建

NSArray * arr = @[@"北京",@"上海",@"天津",@"广州",@"深圳",@"浙江",@"杭州",@"丽江"];
    HLPopTableView * hlPopView = [HLPopTableView initWithFrame:CGRectMake(0, 0, sender.width, 200) dependView:sender textArr:arr block:^(NSString *region_name, NSInteger index) {
    }];
    [self.view addSubview:hlPopView];
  1. dependView: 弹窗的依赖视图,比如点击按钮,直接将按钮控件传入,就会在下方创建弹出的tableView

相关代码

1.创建自定义的弹窗视图,继承于UIView,.h中申明方法

@interface HLPopTableView : UIView

@property(nonatomic, assign)BOOL isTop;
@property (nonatomic, copy) void(^sendStrBlock)(NSString *, NSInteger);


+ (instancetype)initWithFrame:(CGRect)frame dependView:(UIView *)view textArr:(NSArray *)textArr block:(void(^)(NSString * region_name, NSInteger index))block;

@end

2.在.m中的话只要创建就完事了,并没有什么难点。具体的代码可以去Demo中下载查看。

最后附上代码链接:

gibHub地址: https://github.com/MrBMask


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK