gpt4 book ai didi

ios - 返回 View 时保留 UIPickerView 行

转载 作者:行者123 更新时间:2023-11-28 09:17:16 25 4
gpt4 key购买 nike

我一直在尝试在我的应用中添加一些代码,以确保保留之前在选择器 View 中选择的行,以便当用户返回该 View 时,它会显示他们之前选择的行。

我认为我这样做是正确的,但它似乎对我当前的代码没有任何作用。

这是我的:

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
itemSelected = colours[row]
}

override func viewWillAppear(animated: Bool) {
var colourNum = 0
if itemSelected == "Moss" {
colourNum = 0
} else if itemSelected == "Ocean" {
colourNum = 1
} else if itemSelected == "Maroon" {
colourNum = 2
} else if itemSelected == "Steel" {
colourNum = 3
} else if itemSelected == "Iron" {
colourNum = 4
} else if itemSelected == "Cayenne" {
colourNum = 5
}
colourPicker.selectRow(colourNum, inComponent: 0, animated: true)
}

有什么想法吗?

最佳答案

您可以使用 NSUserDefaults。

NSUserDefaults.standardUserDefaults().setObject(newValue, forKey: "selectedColour")
NSUserDefaults.standardUserDefaults().synchronize()

var returnValue: [NSNumber]? = NSUserDefaults.standardUserDefaults().objectForKey("selectedColour") as? [NSNumber]

关于ios - 返回 View 时保留 UIPickerView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26985547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com