繁体   English   中英

按下按钮时未从数组填充UILabel

[英]UILabel Not Populated From Array When Button Pressed

我有一个UITableViewController使用自定义UITableViewCells它含有UILabelUIButton

问题在于,当按钮更改数组中的特定值时,最初设置为0的UILabel不会更改。 当我使用println() ,实际的数组已更改,但UILabel并未更改。

以下是我的UITableViewController的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let groupChatCell = tableView.dequeueReusableCellWithIdentifier("groupChatCell", forIndexPath: indexPath) as textCell

    groupChatCell.voteScoreLabel.text="\(groupVote[indexPath.row])"
    groupChatCell.voteScoreLabel.tag=indexPath.row

    return groupChatCell
}

voteScoreLabel是我要从数组更新的UILabel groupVote是用于用分数填充标签的array 我将UILabel标记设置为等于其索引路径,以便当我需要选择数组的特定值时可以引用它。


以下是我的自定义UITableViewCellController

@IBAction func upVoteButtonPressed(sender: AnyObject) {
    groupVote[voteScoreLabel.tag]=groupVote[voteScoreLabel.tag]+1
}


我在这里做错了什么,以便可以在数组中对应的值更改后更改UILabel

单击按钮时,您需要重新加载tableView数据。 reloadData()函数再次调用每个tableView委托/数据源方法,如果将其UITableViewController添加到整个控制器,则重新加载整个控制器;如果将其视图添加到另一个控制器,则重新加载整个tableView

您的代码应如下所示:

@IBAction func upVoteButtonPressed(sender: AnyObject) {
   groupVote[voteScoreLabel.tag]=groupVote[voteScoreLabel.tag]+1
   instance_of_your_tableView.reloadData()
   // If this is the name of method in swift //
}

问候

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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