相关疑难解决方法(0)

swift UIAlertController与pickerView按钮操作熬夜

我是新手,我正在尝试UIAlertContoller用,PickerView 但我有问题,巴顿斯,这里有一张照片

在此输入图像描述

当我试图改变约束时按钮保持不动我在这里读了很多答案,但我没有找到任何solotuin

这是我的代码:

func distance(){
    let editRadiusAlert = UIAlertController(title: "Choose distance", message: "", preferredStyle: UIAlertControllerStyle.alert)
    let pickeViewFrame: CGRect = CGRect(x: 0, y: 0, width: 250, height: 300)
    let pickerViewRadius: UIPickerView = UIPickerView(frame: pickeViewFrame)
    pickerViewRadius.delegate = self
    pickerViewRadius.dataSource = self
    editRadiusAlert.view.addSubview(pickerViewRadius)
    editRadiusAlert.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.default,handler:nil))
    editRadiusAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
    editRadiusAlert.view.addConstraint(NSLayoutConstraint(item: editRadiusAlert.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.5))
    self.present(editRadiusAlert, animated: true, completion: nil)
} 
Run Code Online (Sandbox Code Playgroud)

xcode uipickerview swift uialertcontroller swift3

13
推荐指数
1
解决办法
9167
查看次数

swift ios 将日期选择器添加到 swift 中的警报以使用核心数据保存到本地数据库

我正在使用带有文本字段输入的警报来保存数据,我想知道的是我想向警报添加一个日期选择器,以便用户添加名称和日期。我已经使保存名称成为可能,但我在添加日期选择器代码以及如何将其添加到警报时遇到问题。代码如下。

警报代码:

if indexPath.row == 0 {
    let alert = UIAlertController(title: "Add New Chore", message: "", preferredStyle:
        UIAlertControllerStyle.alert)

    //this is the field where the user add the name
    alert.addTextField(configurationHandler: textFieldHandler)

    let a =  loggedInUsername
    if ((a?.lowercased().range(of: "mother")) != nil) {
        print("true")
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler:{ (UIAlertAction)in

            let newItem : String = (alert.textFields?.first?.text)!
            if !newItem.isEmpty {

                let item = Item(name: newItem)
//                        let item2 = Item(name: newItem2)
                self.saveItemInLocalDB(groceryItem: item!)

                self.setUpCollectionView()

            }
        }))
Run Code Online (Sandbox Code Playgroud)

使用核心数据保存到本地数据库的代码:

func saveItemInLocalDB(groceryItem : Item) {
    let context …
Run Code Online (Sandbox Code Playgroud)

ios swift

6
推荐指数
2
解决办法
7074
查看次数

标签 统计

swift ×2

ios ×1

swift3 ×1

uialertcontroller ×1

uipickerview ×1

xcode ×1