繁体   English   中英

自定义表格视图单元格中的按钮未显示

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM