各位程序員,您好!我有一個挑戰,我需要幫助。我使用自定義樣式單元格建立了一個表格。開關中的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