0
我有一個tableView在我的項目中成功運行。但是,我有一個問題,選擇單元格和更新我的textView連接到tableview在同一viewController.My textView只更新當我做長按on tableViewCell.I想要每次更新textView時單元格被按下。我相信,當我按下單元格取消選擇本身。我的部分代碼如下..TableView didSelect在Swift中響應問題
注: 我用我的不同項目下面的代碼工作沒有issue..I我不知道什麼是錯與此的tableview ....
謝謝提前....
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let CellIdentifier: String = "fontCell"
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath)
let fontName: String = self.fontName[indexPath.row] as! String
UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseInOut, animations: {() -> Void in
cell.textLabel?.text = fontName
cell.textLabel!.font = UIFont(name: self.fontName[indexPath.row] as! String, size: 25)
}, completion: nil)
cell.backgroundColor = UIColor.clearColor()
cell.textLabel?.textAlignment = .Center
cell.textLabel?.textColor = UIColor.whiteColor()
cell.textLabel?.sizeToFit()
cell.textLabel?.adjustsFontSizeToFitWidth = true
cell.selectionStyle = .Default
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//tableView.deselectRowAtIndexPath(indexPath, animated: true)
dispatch_async(dispatch_get_main_queue(), {() -> Void in
let fontName: String = self.fontName[indexPath.row] as! String
self.textView.font = UIFont(name: fontName, size: 20)
})
}
謝謝Moriya。我已經嘗試過你的解決方案。但沒有運氣這就是爲什麼我嘗試dispatch_async。我相信我的tableview控制器物理設置,idont知道有什麼問題呢...... – Joe
didSelectRowAtIndexPath中的代碼是否運行?如果你設置了一個斷點,當你選擇一行時它會停止嗎? – Moriya
謝謝。當我按住單元格/長按按鈕時,代碼工作正常。但是,當我按下單元格的單元格選擇發生,只要提起選定的手指單元格消失,而不是更新目標視圖...並且我不能在代碼中看到任何斷點... – Joe