ios - 更改按钮标题文本不起作用

标签 ios swift

我正在尝试更改 UIButton 标题文本,但它不起作用。我把它放在 UITableView 中。它看起来像这样:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let imageCell = tableView.dequeueReusableCellWithIdentifier("imageCell", forIndexPath: indexPath) as! StoryCell
        let videoCell = tableView.dequeueReusableCellWithIdentifier("videoCell", forIndexPath: indexPath) as! StoryCell
        let blankCell = tableView.dequeueReusableCellWithIdentifier("blankCell", forIndexPath: indexPath) as! StoryCell

        if (userFile[indexPath.item].url!.rangeOfString(".jpeg") != nil) {
            print("imageCell: \(userFile[indexPath.row].url)")

            imageCell.viewstoryButton.setTitle("Vis bildeeee - \(self.createdAt[indexPath.row].timeAgo)", forState: UIControlState.Normal)
            imageCell.viewstoryButton.titleLabel?.textColor  = UIColor.redColor()

            return imageCell
        }
        if (userFile[indexPath.row].url!.rangeOfString(".mp4") != nil) {
            print("videoCell: \(userFile[indexPath.row].url)")

            videoCell.viewstoryButton.setTitle("Vis video - \(self.createdAt[indexPath.row].timeAgo)", forState: UIControlState.Normal)

            return videoCell
        }
        else{
            print("blankCell")
            return blankCell
        }

    }

我有 3 个原型(prototype)单元:imageCellvideoCellblankCell

它们都连接到StoryCell,按钮将会出现,但文本或颜色不会改变。有什么想法吗?

最佳答案

确保您的按钮也作为 socket 连接到您的 Swift 文件

关于ios - 更改按钮标题文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711747/

相关文章:

ios - iAd 未显示在我的应用程序的下载版本中

ios - 更新xcode后出现很多错误

ios - TableView 重新加载数据后 TableView 单元格布局不正确

ios - 如何使用 UITabBarController 打开模式并在关闭时显示最后一个标签栏 View ?

ios - 将音频修剪为视频长度

iphone - 具有键盘按钮样式的 UIButton

ios - 如果在系统设置中关闭隐藏式字幕,则不会显示字幕

swift - 使用委托(delegate)时没有任何反应

ios - 如何快速获取json对象的数组

iOS总结按钮值、计算器概念