[英]button in custom tableview cell not displaying
我有一個UITableView
,每個單元都與一個文件關聯。 表格視圖顯示了來自所有用戶的文件,並且當單元的文件屬於當前用戶時,單元將顯示一個編輯按鈕。 我的cellForRowAtIndexPath
將檢查與文件關聯的userID並將其與當前用戶ID進行比較。 如果ID匹配,則按鈕不會隱藏。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = self.fileTable.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! FileCell
let file = self.tableFiles[indexPath.row]
cell.fileLabel.text = file.title
cell.userLabel.text = file.username
if file.userId != user?.userID
{
cell.editButton.hidden = true
}
cell.editButton.addTarget(self, action:#selector(HomeController.editPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
當用戶登錄並且登錄后首次加載表視圖時,此方法可以正常工作。 但是,當用戶創建要添加到表self.navigationController?.popViewControllerAnimated(true)
的新文件時,將self.navigationController?.popViewControllerAnimated(true)
並重新出現該表視圖。 但是,除非用戶注銷並重新登錄,否則新文件或任何將來添加的文件不會顯示新文件的編輯按鈕。
以下應該可以解決您的問題。
if file.userId != user?.userID
{
cell.editButton.hidden = true
}
else
{
cell.editButton.hidden = false
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.