gpt4 book ai didi

swift - Click Button如何关闭alertController并获取数据

转载 作者:行者123 更新时间:2023-11-28 06:27:51 25 4
gpt4 key购买 nike

//调用UIViewController中的类

    label = TimePickerView()

alertController = UIAlertController(title: " \n\n\n\n\n\n\n\n\n\n", message: "", preferredStyle: UIAlertControllerStyle.alert)

alertController.view.addSubview(label)
// alertController.view.addSubview(samplePicker)
self.present(alertController, animated: true, completion: nil)

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

import UIKit

class TimePickerView: UIPickerView, UIPickerViewDataSource, UIPickerViewDelegate {
var hour:Int = 0
var minute:Int = 0

var samplePicker: UIPickerView = UIPickerView()
var sampleSegment:UISegmentedControl = UISegmentedControl ()
var alertController:UIAlertController = UIAlertController()



required internal init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.setup()
}

override init(frame: CGRect) {
super.init(frame: frame)
self.setup()

}

func setup(){

self.delegate = self
self.dataSource = self

samplePicker = UIPickerView(frame: CGRect(x:10.0, y:40.0, width:10, height:150))
samplePicker.delegate = self
samplePicker.dataSource = self
samplePicker.showsSelectionIndicator = true
samplePicker.tintColor = UIColor.red
samplePicker.reloadAllComponents()


sampleSegment = UISegmentedControl(items: NSArray(object: "تایید") as [AnyObject])
sampleSegment.isMomentary = true
sampleSegment.frame = CGRect(x:0, y:0,width:270.0, height:30.0)
sampleSegment.tintColor = UIColor.black
sampleSegment.backgroundColor = UIColor.gray
sampleSegment.addTarget(self, action: #selector(TimePickerView.dismissAlert), for: UIControlEvents.valueChanged)

self.addSubview(sampleSegment)
self.addSubview(samplePicker)




}



public func numberOfComponents(in pickerView: UIPickerView) -> Int {

return 2

}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch component {
case 0:
self.hour = row
print(row)
case 1:
self.minute = row
default:
print("No component with number \(component)")
}
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return 24
}

return 60
}

private func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> Int {
return 30
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {


if component == 0 {

return String(row)

}else {

return String(row)
}



}
func dismissAlert(){

alertController.dismiss(animated: true, completion: nil)



}

}

最佳答案

使用 AddAction,UIAlertController 的一个实例属性。

关于swift - Click Button如何关闭alertController并获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41327550/

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