我在每個單元格中使用帶有複選框按鈕的UITableView。當用戶點擊該單元格或按鈕時,該按鈕的圖像必須更改爲「選定」圖像。但是當我點擊任何單元格或按鈕時,圖像沒有變化。無法更改UItableViewcell的圖像按鈕
這裏是我的表碼:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell : categoryCell = tableView.dequeueReusableCellWithIdentifier("categoryCell") as! categoryCell
let dic : NSDictionary = categoryitem.objectAtIndex(indexPath.row) as! NSDictionary
cell.category_name.text = dic.valueForKey("category_name") as? String
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return categoryitem.count
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell : categoryCell = tableView.dequeueReusableCellWithIdentifier("categoryCell") as! categoryCell
cell.category_button.setImage(UIImage(named: "check_checkbox"), forState: UIControlState.Normal)
let dic : NSDictionary = categoryitem.objectAtIndex(indexPath.row) as! NSDictionary
print(dic.valueForKey("category_id") as! String)
}
您是否在categoryCell中爲imageView創建了IBOutlet? –
但我想更改uibutton的圖像。所以我創建了uibutton的iboutlet @SandeepBhandari –
對不起,我的意思是UIButton:D –