zoukankan      html  css  js  c++  java
  • Swift项目使用SWTableViewCell

    SWTableViewCell的功能是添加TableViewCell的侧滑按钮(包括左滑和右滑按钮)
     
    它是用OC写的,可以用pod安装,也可以直接导入到项目中去,但是如果是swift项目,pod中已经安装了其他的一些库,可能会出现编译的问题,所以这里我就没有使用pod,直接导入到项目中:
     
    1 下载SWTableViewCell项目代码
     
    2 将其中的项目类文件(podfiles文件夹下的)copy到自己的swift项目中去:
     
     在项目桥接文件(Bridging-Header.h)中添加
     
    #import “SWTableViewCell"
     
    (这里编译的时候有个问题,“NSMutableArray+SWUtilityButton.h”会编译出错,可能是因为少了引用#import <UIKit/UIkit.h>的缘故,添加以下就可以了)
     
    4 下面就可以使用SWTableViewCell了
     
    让自己的tableViewCell继承自SWTableViewCell
     
    比如想要添加右边的侧滑按钮“修改”
    可以在tableViewCell中添加方法
     
    func addSwipeRightButtons() -> Void{
            var rightButtons : [AnyObject] = [AnyObject]()
           
            var deleteButton = UIButton()
            deleteButton.backgroundColor = ZMColor.CellEdit.toUIColor()
            deleteButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
            deleteButton.setTitle("修改", forState: .Normal)
            deleteButton.titleLabel?.adjustsFontSizeToFitWidth = true
            rightButtons.append(deleteButton)
    
            self.rightUtilityButtons = rightButtons
    }
    
    然后在UITableViewDelegate中的canEditRowAtIndexPath方法中return false来禁止系统自带的一个删除选项
     
    同时在cellForRowAtIndexPath中cell.delegate = self 
     
    然后实现SWTableViewCell的delegate
     
    extension ViewController: SWTableViewCellDelegate{
        func swipeableTableViewCell(cell: SWTableViewCell!, didTriggerRightUtilityButtonWithIndex index: Int) {
            switch index{
            case 0:
                UIAlertView(title: "通知", message: “点击了修改按钮", delegate: nil, cancelButtonTitle: "确定").show()
                break
            default:
                break
    }
    

    (注意: 因为TableViewCell继承了SWTableViewCell,因此如果在自己的tableViewCell中添加一个delegate,那么名字就不能叫”delegate”了,因为SWTableViewCell本身就有一个,这样会编译出错了)

     
     
     
     
     
  • 相关阅读:
    免费的论文查重网站
    文件上传到tomcat服务器 commons-fileupload的详细介绍与使用
    消防喷头的原理
    [辟谣]下蹲猛起来眼前发黑是心脏衰竭的表现?别扯了!
    noip2010普及组 接水问题分析
    洛谷P1106 删数问题
    老飞侠随机抽取器 v3.0 新春钜惠版
    一个基于VB的简单IRC机器人服务器
    (转)经常有人发错 SQL 的发音,如何华丽丽的引导纠正他们又不失优雅?
    TONGHUA
  • 原文地址:https://www.cnblogs.com/rambot/p/4417443.html
Copyright © 2011-2022 走看看