Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iAction更新tableviewcontroller中的每个单元格行_Ios_Iphone_Swift_Uitableview_Tableview - Fatal编程技术网

Ios iAction更新tableviewcontroller中的每个单元格行

Ios iAction更新tableviewcontroller中的每个单元格行,ios,iphone,swift,uitableview,tableview,Ios,Iphone,Swift,Uitableview,Tableview,我有一个表视图单元格和UITableViewController。我在表视图单元格中有两个IBOutlets(喜欢/不喜欢)。我在TableViewController中还有两个iActions。单击iActions时,它会更新表视图中的每个单元格。这是我的密码: 表视图控制器: class UserFeedTableViewController: PFQueryTableViewController { var shouldReloadOnAppear: Bool = true // Vot

我有一个表视图单元格和
UITableViewController
。我在表视图单元格中有两个IBOutlets(喜欢/不喜欢)。我在TableViewController中还有两个iActions。单击iActions时,它会更新表视图中的每个单元格。这是我的密码:

表视图控制器:

class UserFeedTableViewController: PFQueryTableViewController {
var shouldReloadOnAppear: Bool = true

// Votes: -1 for dislike, 1 for like, 0 for no vote
var vote: Int = 0 // initialize to user's existing vote, retrieved from the server
var likeCount: Int = 0 // initialize to existing like count, retrieved from the server
var dislikeCount: Int = 0 // initialize to existing dislike count, retrieved from the server

@IBAction func dislikeButton(sender: UIButton) {

buttonWasClickedForVote(-1)

self.tableView.reloadData()
print(likeCount)
print(dislikeCount)
}

}

}

}

表视图单元格:

class UserFeedCell: PFTableViewCell {

@IBOutlet weak var likeButton: UIButton!

@IBOutlet weak var dislikeButton: UIButton!

var post: PFObject? {
 didSet{   
  }
}
}

请更详细地描述您的问题,您的问题到底是什么还不完全清楚。将其添加到帖子中,以便人们在开始阅读您的帖子时立即看到它!因此,当我按下“喜欢/不喜欢”按钮时,每个单元格的标题和按钮状态都会发生变化。我想让它只对用户按下的那个按钮进行更改。这是第三个版本,不清楚的是,两个按钮,在按下时与单元格分开,必须更新特定单元格的数据。如果您只有两个按钮,是在按下时选择了单元格,还是在每个单元格上都有另外两个按钮,通过按下按钮生成操作表单yor
TableViewController中的两个全局按钮?请检查我的代码。我只有两个按钮。当我按下任何一个按钮时,每个按钮的状态、title get updated.likeCount和dislikeCount都由视图控制器类UserFeedTableViewController管理。单击按钮时,更新其中一个值,然后调用reloadData。这将使用likeCount/dislikeCount的新更新值重新加载整个表,因此所有单元格都将具有新值。这是你的意图吗?或者,您是否打算为单元格指定一个单独的likeCount/dislikeCount?请更详细地描述您的问题,您的问题到底是什么还不完全清楚。将其添加到帖子中,以便人们在开始阅读您的帖子时立即看到它!因此,当我按下“喜欢/不喜欢”按钮时,每个单元格的标题和按钮状态都会发生变化。我想让它只对用户按下的那个按钮进行更改。这是第三个版本,不清楚的是,两个按钮,在按下时与单元格分开,必须更新特定单元格的数据。如果您只有两个按钮,是在按下时选择了单元格,还是在每个单元格上都有另外两个按钮,通过按下按钮生成操作表单yor
TableViewController中的两个全局按钮?请检查我的代码。我只有两个按钮。当我按下任何一个按钮时,每个按钮的状态、title get updated.likeCount和dislikeCount都由视图控制器类UserFeedTableViewController管理。单击按钮时,更新其中一个值,然后调用reloadData。这将使用likeCount/dislikeCount的新更新值重新加载整个表,因此所有单元格都将具有新值。这是你的意图吗?或者您是否打算为单元格指定一个单独的likeCount/dislikeCount?
private func buttonWasClickedForVote(buttonVote: Int) {
if buttonVote == vote {
    // User wants to undo her existing vote.
    applyChange(-1, toCountForVote: vote)
    vote = 0
}

else {
    // User wants to force vote to toggledVote.
    // Undo current vote, if any.
    applyChange(-1, toCountForVote: vote)

    // Apply new vote.
    vote = buttonVote
    applyChange(1, toCountForVote: vote)
}
private func applyChange(change: Int, toCountForVote vote: Int ) {
if vote == -1 { dislikeCount += change }
else if vote == 1 { likeCount += change }
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let CellIdentifier = "Cell"

    var cell: UserFeedCell? = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath) as? UserFeedCell

    if cell == nil {
        cell = UserFeedCell(style: UITableViewCellStyle.Default, reuseIdentifier: CellIdentifier)

    }

    if object != nil {
        cell!.likeButton.selected = vote == 1

        cell!.dislikeButton.selected = vote == -1
        cell!.likeButton.setTitle("\(likeCount)", forState: .Normal)
        cell!.dislikeButton.setTitle("\(dislikeCount)", forState: .Normal)

    }

return cell
}
class UserFeedCell: PFTableViewCell {

@IBOutlet weak var likeButton: UIButton!

@IBOutlet weak var dislikeButton: UIButton!

var post: PFObject? {
 didSet{   
  }