有关如何构建我的应用程序的建议

问题描述 投票:-3回答:1

我有一个UIPickerView,有几个不同的位置。现在,当用户选择所有发生的位置时,会显示一个按钮并更改背景图像。连接按钮后,我希望下一个视图是从该位置显示的用户列表(用户将从Firebase获取)。我想就如何解决这个问题提出一些建议,我不确定最好的方法是使用协议,容器视图还是segues。如果它有任何区别,它也是带有3个选项卡的选项卡式应用程序。其他选项卡是设置和配置文件选项卡。 location picker location picked

class LocationPickerViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {


@IBAction func locationAction(_ sender: Any) {
}

@IBOutlet weak var locationButton: UIButton!


let locationsArray = ["Please Select your location","San Francisco", "Los Angeles", "Las Vegas", "Chicago","New York","Miami"]

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return locationsArray[row]
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return locationsArray.count
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let label = (view as? UILabel) ?? UILabel()

    label.textColor = .white
    label.textAlignment = .center
 //   label.font = UIFont(name: "SanFranciscoText-Light", size: 50)
    label.font = UIFont.systemFont(ofSize: 30)
    // where data is an Array of String
    label.text = locationsArray[row]

    return label
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
    return 50.0
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if(row == 0)
    {
        locationLabel.text = "Select Location"

        locationButton.isHidden = true
       self.view.backgroundColor = UIColor.black

    }
   else if(row == 1)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("SF", for: .normal)
         self.view.backgroundColor = UIColor(patternImage: UIImage(named: "SF")!)


    }
    else if(row == 2)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("LA", for: .normal)
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "LA")!)
    }
    else if(row == 3)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("Las Vegas", for: .normal)
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "LV")!)
    }
    else if(row == 4)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("Chicago", for: .normal)
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "Chicago")!)
    }
    else if(row == 5)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("New York", for: .normal)
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "NY")!)
    }
    else if(row == 6)
    {
        locationLabel.text = locationsArray[row]
        print(locationsArray[row])
        locationButton.isHidden = false
        locationButton.setTitle("MIAMI", for: .normal)
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "Miami")!)
    }


}

@IBOutlet weak var locationLabel: UILabel!


@IBOutlet weak var locationPicker: UIPickerView!

override func viewDidLoad() {
   locationPicker.backgroundColor = UIColor.black
    locationPicker.alpha = 0.6
    locationButton.isHidden = true
    super.viewDidLoad()
   self.locationPicker.selectRow(0, inComponent: 0, animated: true)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

ios swift uipickerview
1个回答
0
投票

使用按钮作为segue将是解决此问题的最有效方法,只需在故事板中创建一个新控制器,然后右键单击该按钮即可创建一个简单的segue。

© www.soinside.com 2019 - 2024. All rights reserved.