iOS 11 开发第一季 初级篇

来到初级篇

默认教学计划
708人加入学习
(0人评价)
价格 免费
教学计划
承诺服务

    var weapons = ["AUG","AWM","十字弩","DP28","Groza","Kar98K","M16A4","Micro UZI","平底锅","SKS","UMP9"]

    var weaponTypes = ["自动步枪","狙击枪","冷兵器","机枪","自动步枪","狙击枪","自动步枪","冲锋枪","近战武器","半自动步枪","冲锋枪"]

    var origins = ["奥地利","英国","中国","前苏联","俄罗斯","德国","英国","以色列","美国","前苏联","美国"]

    var weaponImages = ["aug","awm","crossbow","dp28","groza","kar98k","m16a4","microuzi","pan","sks","ump9"]

[展开全文]

let favAction = UIContextualAction(style: .normal, title: "favrite") { (_, _, completion) in

            self.favorites[indexPath.row]   = !self.favorites[indexPath.row] //存储信息取反

            let cell = tableView.cellForRow(at: indexPath) as! WeaponsTableViewCell

            cell.favorite    =  self.favorites[indexPath.row] //更新favorit状态解决重复利用bug

            

            completion(true)

 

//实现左侧收藏

[展开全文]

tableVew.deleteRows(at:[indexPath],with:.automatic) //更新视图内容

[展开全文]

let btnPos= sender.convert(CGpoint.zero,to: self.tableView) //获取按钮位置

let indexPath = tableView.indexPathForRow(at:btnPos)!

//转换为单元格位置

self.favorites[indexPath.row] = !self.favorites[indexPath]

//数组相应内容取反(重复点击交换状态)

[展开全文]

cell.favorite =favorites[indexPath.row] //解决单元格复用

[展开全文]

如果用三元运算符的话可以只用两行实现吧?

var 图标 = newValue ? '实心' : '空心';

favBtn.setImage(图标, for: .normal);

 

[展开全文]

授课教师

Swift小菜

课程特色

视频(21)

学员动态