Swift调用OC方法

Swift调用OC类方法(方法中有Block作为参数传递解决方法)

OC代码


  • @param frame 尺寸
  • @param selectData 选择控件的数据源
  • @param action 点击回调方法
  • @param animate 是否动画弹出
+ (void)addPellTableViewSelectWithWindowFrame:(CGRect)frame
                                   selectData:(NSArray *)selectData
                                       images:(NSArray *)images
                                    showPoint:(CGPoint)showPoint
                                       action:(void(^)(NSInteger index))action animated:(BOOL)animate;

Swift中调用


    func rightBtnClick(){
        HWPrint("点击了加号按钮")
        LKSMenuShowView.addPellTableViewSelect(withWindowFrame:CGRect(x: view.bounds.size.width-100, y: 64+5, width: 110, height: 200) , selectData: titles, images: iconStrings, show: CGPoint(x: 200, y: 10), action: {(index) -> () in
           self.selectButtonWithIdex(index: index)
        }, animated: true)
    }
    func selectButtonWithIdex(index : NSInteger) {
        HWPrint(index)
        switch index {
        case 0:
            HWPrint("点击了扫描添加")
        case 1:
            HWPrint("点击了手动输入添加")
        default: break
        }
    }

代码解说


OC中Block部分 action:(void(^)(NSInteger index))action
                         转换
Swift中闭包   action: {(index) -> () in  要处理的事件}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容