Objective c 更改pickerView组件位置

Objective c 更改pickerView组件位置,objective-c,swift,io,swift2,uipickerview,Objective C,Swift,Io,Swift2,Uipickerview,我有一个带有两个组件的pickerView。根据我的语言,我需要更改组件的位置,使第一个组件位于右侧,第二个组件位于左侧 这就是我想做的: 注意:组件是连接的,我的意思是从第一个组件中选择一行,第二个组件将重新加载新内容 我该怎么做 更新 代码如下: func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { if IS_Mahalat {

我有一个带有两个组件的
pickerView
。根据我的语言,我需要更改组件的位置,使第一个组件位于右侧,第二个组件位于左侧

这就是我想做的:

注意:组件是连接的,我的意思是从第一个组件中选择一行,第二个组件将重新加载新内容

我该怎么做

更新

代码如下:

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    if IS_Mahalat {  
        return 1
    }else{ // just ostan - shahrestan
        if component == 0  {  //osatn
            return self.ostans.count
        }else{//shahrestan
            return self.ostans[pickerView.selectedRowInComponent(0)]._city.count
        }
    }

}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    if IS_Mahalat {  
        //return self.mahalat[row].name
        return "sdf"
    }else{//ostan shahrestan
        if component == 0  {  //osatn
            return self.ostans[row].name
        }else{//shahrestan
            print(pickerView.selectedRowInComponent(0))
            return  self.ostans[pickerView.selectedRowInComponent(0)]._city[row]._name
        }
    }
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    if !IS_Mahalat {//ostan shahrestan
        if component == 0  {  
             self.picker_ostan.reloadComponent(1)
        }
    }
}

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
    var myString = view as! UILabel!
    let rowText:String!


    if( view == nil) {
        myString = UILabel()
    }
    if IS_Mahalat {  
        rowText = ""
    }else{  //ostan shahrestan

        if component == 0  {  //osatn
             rowText = self.ostans[row].name
        }else{//shahrestan
             rowText = self.ostans[pickerView.selectedRowInComponent(0)]._city[row]._name
        }
    }
    myString.textAlignment = .Center
    let attributedRowText = NSMutableAttributedString(string: rowText)
    let attributedRowTextLength = attributedRowText.length

    attributedRowText.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSRange(location: 0, length: attributedRowTextLength))

    attributedRowText.addAttribute(NSFontAttributeName, value: UIFont(name: FONT_NAME, size: 16.0)!, range: NSRange(location: 0 ,length:attributedRowTextLength))

    myString!.attributedText = attributedRowText



    return myString

}


func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    if IS_Mahalat {  
        return 1
    }else{ // just ostan - shahrestan
        return 2
    }
}

只需交换两个选择器源并重新加载它。难道你没有两个数组吗?交换一下他们的contents@LeoDabus不,我有一个名为ostan的类。我创建了一个ostan类型的数组,它有一个属性,它是一个数组,它生成第二个组件