我正在尝试更改 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)单元:imageCell
、videoCell
和 blankCell
。
它们都连接到StoryCell
,按钮将会出现,但文本或颜色不会改变。有什么想法吗?
最佳答案
确保您的按钮也作为 socket 连接到您的 Swift 文件
关于ios - 更改按钮标题文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711747/