大佬教程收集整理的这篇文章主要介绍了在tableviewcell的附件视图中的UISwitch,通过选择器传递参数以具有选择器功能,请参见indexpath.row?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
let lightSwitch = UISwitch(frame: CGRectZero) as UISwitch
lightSwitch.on = false
lightSwitch.addTarget(self, action: #SELEctor(switchtriggered), forControlEvents: .ValueChanged)
lightSwitch.tag = indexpath.row
cell.accessoryVIEw = lightSwitch
让我们将布尔值保存在数组中
func switchtriggered(sender: UISwitch) {
sender.on ? arraY[sender.tag]=1 : arraY[sender.tag]=0
}
}
我UISwitch
在tableviewcontroller中有一个,当切换开关时,我希望它更改在单元格相关的视图控制器内部创建的数组中的布尔变量的值。有点像IOS上的Stock
Alarm
App,其中每个单元都有一个UISwitch
,并且拨动该开关将关闭每个单独的警报。因此,使用UISwitch
,其选择器代码位于cellForRowATindexPath
方法内部
//switch
let lightSwitch = UISwitch(frame: CGRectZero) as UISwitch
lightSwitch.on = false
lightSwitch.addTarget(self,action: #SELEctor(switchtriggered),forControlEvents: .ValueChanged)
//lightSwitch.addTarget(self,action: "switchtriggered",forControlEvents: .ValueChanged )
cell.accessoryView = lightSwitch
我希望它做到这一点
func switchtriggered(a: int) {
changeValueOfArray = arraY[indexPath.row]
}
我还没有为那部分编写代码,但是我的问题是,如何让switchtriggered函数看到该indexPath.row
值,而不将其作为参数传递给该函数,因为我不能因为它的选择器?
以上是大佬教程为你收集整理的在tableviewcell的附件视图中的UISwitch,通过选择器传递参数以具有选择器功能,请参见indexpath.row?全部内容,希望文章能够帮你解决在tableviewcell的附件视图中的UISwitch,通过选择器传递参数以具有选择器功能,请参见indexpath.row?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。