swift-tableView 代理方法实现点击按钮删除效果
来源:互联网 发布:什么软件画平面图 编辑:程序博客网 时间:2024/06/06 01:19
import UIKitprotocol FirstTableViewCellDelegate: NSObjectProtocol { func deleteCell(cell: FirstTableViewCell, button: UIButton)}class FirstTableViewCell: UITableViewCell { @IBOutlet weak var myLabel: UILabel! @IBOutlet weak var myButton: UIButton! weak var delegate:FirstTableViewCellDelegate? override func awakeFromNib() { super.awakeFromNib() prepareUI() // Initialization code } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } func prepareUI() { myButton.setTitle("删除", forState: UIControlState.Normal) myButton.backgroundColor = UIColor.redColor() myButton.layer.cornerRadius = 15 myButton.layer.masksToBounds = true myButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal) myButton.addTarget(self, action: "BtnClick:", forControlEvents: UIControlEvents.TouchUpInside) } @objc private func BtnClick(button:UIButton){ delegate?.deleteCell(self, button: button) } }
import UIKitclass FirstViewController: UIViewController { @IBOutlet weak var tableView: UITableView! let cellIdentified = "cell" var numbers = ["One","Two","Three","Foure","Five","Six","Seven","Eight","Nine","Ten"]; override func viewDidLoad() { super.viewDidLoad() // 准备UI prepareUI() // Do any additional setup after loading the view. } private func prepareUI() { navigationItem.title = "首页" tableView.delegate = self tableView.dataSource = self // tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIdentified) tableView.registerNib(UINib(nibName: "FirstTableViewCell", bundle: nil), forCellReuseIdentifier: cellIdentified) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if editingStyle == UITableViewCellEditingStyle.Delete { numbers.removeAtIndex(indexPath.row) tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }extension FirstViewController:UITableViewDelegate, UITableViewDataSource, FirstTableViewCellDelegate { func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentified, forIndexPath: indexPath) let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentified, forIndexPath: indexPath) as! FirstTableViewCell // cell.textLabel?.text = numbers[indexPath.row] cell.myLabel.text = numbers[indexPath.row] cell.delegate = self cell.selectionStyle = UITableViewCellSelectionStyle.None return cell } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return numbers.count } func deleteCell(cell: FirstTableViewCell, button: UIButton) { let idx:NSIndexPath = tableView.indexPathForCell(cell)! numbers.removeAtIndex(idx.row) tableView.deleteRowsAtIndexPaths([idx], withRowAnimation: UITableViewRowAnimation.Top) }}
0 0
- swift-tableView 代理方法实现点击按钮删除效果
- 按钮点击效果的简单实现方法
- tableView cell 左滑点击删除等点击按钮
- Java实现按钮隐藏点击动态效果的另类方法
- 点击按钮实现倒计时效果
- selector实现按钮点击效果
- swift下tableview的使用(cell点击伸缩效果)
- 解决tableview上按钮点击效果的延迟现象
- tableView滑动出现删除按钮,不点击就返回崩溃
- swift-tableView 删除行
- tableview隐藏点击效果
- tableview添加删除按钮
- ios tableview 删除按钮
- 点击TableView的Cell没有不走代理方法
- Swift防止按钮重复点击实现+Swift如何运用Runtime
- android 关于按钮点击效果的方法
- 点击按钮实现遮罩效果
- 代码实现按钮点击高亮效果
- 循环链表
- CAGradientLayer处理颜色渐变效果
- EventBus基础教程解析,一分钟学会EventBus的使用
- Linux查看开机运行时间的多种方法
- 正则化方法:L1和L2 regularization、数据集扩增、dropout
- swift-tableView 代理方法实现点击按钮删除效果
- Java 获取用户请求ip
- 采用dlopen、dlsym、dlclose加载动态链接库
- easyui combotree 异步加载节点 默认值 问题
- 开发积累
- CSS布局奇淫技巧之-高度自适应
- apt-get install时遇到 Sub-process /usr/bin/dpkg returned an error code (1)
- 【证明】加减法交换两个整数,过程可能会溢出,但结果依然正确
- 建立Android5.1.1编译环境