2017-11-20 4 views
-3

여러 위치가있는 UIPickerView가 있습니다. 현재 사용자가 위치를 선택하면 버튼이 나타나고 배경 이미지가 변경됩니다. 버튼이 연결되면 다음 뷰를 해당 위치에서 표시된 사용자 목록으로보고 싶습니다 (사용자는 Firebase에서 가져옵니다). 이 문제를 해결하는 방법에 대한 조언을 원합니다. 프로토콜, 컨테이너 뷰 또는 세그먼트를 사용하는 것이 가장 좋은 방법인지 확신 할 수 없습니다. 차이가 있다면 3 탭이있는 탭 응용 프로그램입니다. 다른 탭은 설정 및 프로필 탭입니다. 이 문제를 해결하기위한 가장 효율적인 방법이 될 것 SEGUE로 버튼을 사용하여 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. 
} 

}

답변

0

는 그냥보기로 스토리 보드와 마우스 오른쪽 버튼으로 클릭 드래그에서 버튼을 새 컨트롤러를 만들 간단한 segue를 만들 수 있습니다.

관련 문제