0
我需要幫助。我試圖設置一個模糊的視圖,當我點擊一個單元格時出現。我不知道是否有任何功能來檢測單元格是否觸摸,所以我使用「選定」布爾值來檢查它是否被選中/觸摸。之後,如果圖像陣列中有圖像,我想在模糊的視圖中顯示它。很多應用程序,可能不是這樣,但那是我找到的唯一方法。 當我測試它時,選擇仍然出現,但沒有發生任何事情,就像這段代碼從未執行過一樣。如果即使警報出現,我也會知道它正在工作,但事實並非如此。爲什麼不能識別細胞的選擇? Swift
觀察:cellImgView是我添加的一個UIView,主要用於放置圖像描述,圖像和關閉按鈕以及模糊視圖。所有這些都被設置爲隱藏在界面生成器中,因爲我只想在單元格被觸摸時取消隱藏它們。
此代碼中的函數:
tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
下面是代碼
if cell.selected == true { //!
if let dataArr = dft.valueForKey("images") as? [NSData] {
let nowImgData = dataArr[indexPath.row]
let nowImg = UIImage(data: nowImgData)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurView = UIVisualEffectView(effect: blurEffect)
theCellView.addSubview(blurView)
blurView.frame = theCellView.bounds
theCellView.hidden = false
theCellImgViewCloseBtn.hidden = false
theCellImageDesc.hidden = false
theCellImage.hidden = false
theCellImage.image = nowImg
theCellImageDesc.text = descriptions[indexPath.row]
} else {
let alert = UIAlertController(title: "No image", message: "This cell has no image", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(alert, animated: true, completion: nil)
}
}
任何幫助表示讚賞!
這可能會有幫助嗎?這個代碼在這個函數裏面... –
@HenriqueDourado我提供的函數是用於單元格選擇的。這是不一樣的。 – Shen
哦,我的壞。讓我嘗試一下,我會給你一個反饋。謝謝 –