2016-04-27 76 views
0

我累了選擇器視圖ie(貨幣),(id)和顯示的兩個組件,但我的問題是如何在選擇器視圖中單獨隱藏「id」組件。和responseArray1中的「id」。選擇器查看一個組件隱藏和其他組件隱藏

選擇器視圖代表:

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{ 
    return 2; 

} 
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;{ 
     return [responseArray count]; 
    } 

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;{ 
    //return [responseArray objectAtIndex:row]; 
    if (component == 0) { 
     return [responseArray objectAtIndex:row]; 
    } else { 
     return [responseArray1 objectAtIndex:row]; 


    } 
} 

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; 
{ 

    NSLog([responseArray1 objectAtIndex:row]); 
    if (component == 0) { 
     [pickerView selectRow:row inComponent:1 animated:YES ]; 
    } else if(component == 1) 
    { 
     if (row != [pickerView selectedRowInComponent:0]) 
     { 
      [pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:1 animated:YES]; 
     } 

    } 
} 
+0

那麼,你想要什麼?沒有正確地得到你的問題 – Lion

+0

兩個組件在選取器視圖中一個組件想要隱藏並且其他組件想要取消隱藏@Lion –

+0

當想隱藏並且想要取消隱藏時?如果一次只需要一個組件,那麼爲什麼你返回2? – Lion

回答

0

回答按評論:

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{ 
return 1; 

} 
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ 
return [responseArray count]; 
} 

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ 


return [responseArray objectAtIndex:row]; 



} 

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 

NSLog(@"rsponse currency : %@",[responseArray objectAtIndex:row]); 
NSLog([responseArray1 objectAtIndex:row]); 



// You can fetch value from both array using row parameter. 
// You can display currency and id for particular row from here like above 

} 

你不需要顯示在pickerview雙組份。只要顯示一個你想要顯示的,並根據選定的行,你可以從數組中獲取相應的元素。

希望這會有所幫助:)

+0

不客氣.... :)如果你認爲這是有幫助的,那麼upvote答案:) – Lion