我創建了一個自定義單元的實現代碼如下。更新表格單元格變量的值之後
裏面我的UITableViewCell文件我有以下代碼:
var myTipView:EasyTipView?
@IBAction func infoBtn_pressed(_ sender: UIButton) {
//print(diseases)
if self.myTipView == nil
{
self.myTipView = EasyTipView(text: diseases, preferences: EasyTipView.globalPreferences)
self.myTipView!.show(forView: sender)
}
else
{
self.myTipView!.dismiss()
self.myTipView = nil
}
}
和我的UIViewController裏面我與代碼實現代碼如下:
var myTipView:EasyTipView?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTable.dequeueReusableCell(withIdentifier: "diffCell") as! diffCell
cell.myTipView = self.myTipView
}
的時候我試圖用自己的價值.myTipView我發現它零,這是顯而易見的,因爲直到infoBtn_pressed被激活,它沒有任何價值,在這種情況下cell.myTipView始終爲零當表第一次創建
我怎樣才能按下按鈕,一旦你設置myTipView
值使用它裏面的UIViewController