如何重新加载选择器视图?

时间:2015-04-04 04:00:33

标签: ios xcode swift xcode6 uipickerview

@IBAction func nextTurn(sender: AnyObject) {
    if numberOfTurn < (playersForPicker.count-1) {
    numberOfTurn++
    }else{
        numberOfTurn = 0
    }
    titleForTwo.title = playersForPicker[numberOfTurn]
    var lostPlayer = playersForPicker[numberOfTurn]

    titleForTwo.title = playersForPicker[numberOfTurn]

    playersForPicker.removeAtIndex(numberOfTurn)

    playerPicker.reloadAllComponents()

         playersForPicker.insert(lostPlayer, atIndex: numberOfTurn)
    startButton.setTitle("Next Turn", forState: UIControlState())
}

playerPicker没有重新加载或更改,因此我需要有关如何在单击按钮时刷新或重新加载选取器视图的帮助。

1 个答案:

答案 0 :(得分:0)

为什么要改变?您正在删除playersForPicker [numberOfTurn],但您将lostPlayer设置为相同的值,然后将其添加回阵列中的相同位置。阵列没有改变,所以你的选择器也不会改变。您正在重新加载选择器视图。如果您注释掉插入lostPlayer的行,您应该会看到该项目从选择器中消失。