开发者

iPhone: Multiple UIPickerViews

开发者 https://www.devze.com 2023-03-02 09:44 出处:网络
I use a multiple UIPickerView in iPhone application. My question is, how can开发者_StackOverflow I handle multiple UIPickerView Handle Events?

I use a multiple UIPickerView in iPhone application. My question is, how can开发者_StackOverflow I handle multiple UIPickerView Handle Events?

Also, I want to place the selected value In UITextField of different UIPickerViews.


In each delegate you have reference of the UIPickerView which got triggered the delegate. for instance:

-(void)numberOfComponentInPickerView:(UIPickerView*)thePickerView

You have thePickerView variable which points to the control responded to this action, all you need to do now is to distinguish between your UIPickerViews as the following:

 if (thePickerView == firstPickerView)

Or Using The Tag property

 if (thePickerView.tag == 1)

I would go with the tag solution; comparing int is way faster.

How do I get the selected value:

As for the selected value of UIPickerView you can do that by using the delegate:

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

You will need to use the same technique here; distinguish between your UIPickerView and get the selected row for that data source and you are done

 MyTextField.text = [theSelectedListArray objectAtIndex:row];


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    NSInteger counter;
    if(pickerView==p1)
    {
        counter=[name count];
    }
    else
    {
        counter=[name2 count];
    }
    return counter;

}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if(pickerView==p1)
        return [name objectAtIndex:row];//name is NsMutable Array
    else
        return [name2 objectAtIndex:row];//name2 is NsMutable Array

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号