ios - Swift 3.0 字符串问题

标签 ios iphone swift swift3

我有一个自定义选择器 View ,它工作得很好,但有一个问题。您可以再次单击该按钮,然后选择器 View 将被关闭。但是,当它关闭时,取消按钮中的文本将变为空白并且不会保持不变(“选择”是一个打开选择器 View 的按钮,当您从选择器 View 中选择某些内容以反射(reflect)您选择的内容时,其文本会发生变化。我什么想要发生的情况是,如果您再次单击选择按钮(而不是选择器 View ),那么取消按钮中的文本将不会更改并变为空白。

var pickValue:AnyObject? {
        didSet{
            if let pickValue = pickValue{
                Select.setTitle("\(pickValue)", for: UIControlState())
            }else{
                Select.setTitle("Select", for: UIControlState())
            }
        }
    }

@IBAction func Show(_ sender: AnyObject) {
        let pickercontrol  = LCTableViewPickerControl(
            frame: CGRect(x: 0, y: self.view!.frame.size.height + 150, width: view.bounds.size.width - 50, height: 150),
            title: "Please pick an item",
            value: pickValue,
            items: ["minute", "hour", "day", "month", "year"],
            offset: CGPoint(x: 0, y: 0))
        pickercontrol?.tag = 1
        view.addSubview(pickercontrol!)
        pickercontrol?.show(in: view) { [weak self](sender, item) in
            guard let view = sender as? LCTableViewPickerControl else{
                return
            }
            view.dismiss()
            self?.pickValue = item as AnyObject?
        }


    }

The image when the picker view is initialized and your able to pick a value

Here is a picture of the problem. After you click the button again. The picker view dismisses and the text inside the button becomes blank. I want to change it so that if the view is dismissed and no value is chosen from the picker view then the text inside the button stays the same

最佳答案

您需要设置您想要的 controlState。 对于 UIControlState.normal

关于ios - Swift 3.0 字符串问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925882/

相关文章:

ios - 如何在 UISlider 中显示 AVplayer 当前播放持续时间

iphone - 我的项目中的框架标题出现问题

ios - UITextField 数字小键盘 : dot instead of comma for float values

ios - TextView 中的按钮

javascript - 您可以从 Mobile Safari 访问 iPhone 相机吗?

swift - Xcode 6- SWIFT- 将 CMTime 转换为 Float

ios - 在 Xcode 4.2 中重命名项目

ios - 无法滚动到容器 View 中嵌入的 UITableViewController 的底部单元格

ios - 当独立 RLMObject 具有任何观察到的属性时,无法将其添加到 Realm 中,这是什么意思

iphone - Ipad/Iphone - UIView 中的图像旋转