各位程序员,您好!我有一个挑战,我需要帮助。我使用自定义样式单元格建立了一个表格。开关中的TableView中的UISwitch
这个单元格只有一个Label
和UISwitch
。标签显示一个名称,交换机显示它们是否是管理员。这工作完美。我的挑战是如何在交换机发生变化时将代码作出反应。
所以,如果我点击开关将其从关闭更改为在哪里我可以得到它打印人名?如果我能得到打印的名字,我可以自己做php/sql代码。谢谢,这里是我的代码片段。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
let admin = self.admin[indexPath.row]
let text1a = admin.FirstName
let text1aa = " "
let text1b = admin.LastName
let text1 = text1a + text1aa + text1b
(cell.contentView.viewWithTag(1) as UILabel).text = text1
if admin.admin == "yes" {
(cell.contentView.viewWithTag(2) as UISwitch).setOn(true, animated:true)
} else if admin.admin == "no" {
(cell.contentView.viewWithTag(2) as UISwitch).setOn(false, animated:true)
}
return cell
}
我现在试着得到同样的东西。我已经在UITableViewCell里面实现了IBAction来获取开关值,但是我不知道从TableViewController中获取值的开关值是什么...我缺少什么?我应该在cellForRowAtIndexPath中调用一些东西吗? – 2015-09-15 13:21:50