isarathg
isarathg

Reputation: 878

UIPickerView with two components

I had used the below code to get the row index of the UIPickerView view with two components. But there is two warnings saying "Local declaration of UIPickerView hides the instance variable. Anyone please help.

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

    int pos1 = [pickerView selectedRowInComponent:0];
    NSLog(@"Row1: %i ",pos1);
    int pos2 = [pickerView selectedRowInComponent:1];
    NSLog(@"Row2: %i ",pos2);


}

Upvotes: 0

Views: 899

Answers (1)

glorifiedHacker
glorifiedHacker

Reputation: 6420

You are likely using "pickerView" as the name of your ivar and "pickerView" as the name of one of your input arguments. These conflict and the compiler is warning you that the local one (ie. the input argument of your delegate method) will take precedence. To get rid of this warning, change either the name of your ivar or the name of the argument in your delegate method. For example,

- (void)pickerView:(UIPickerView *)pv didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int pos1 = [pv selectedRowInComponent:0]; NSLog(@"Row1: %i ",pos1);
int pos2 = [pv selectedRowInComponent:1]; NSLog(@"Row2: %i ",pos2);

Upvotes: 1

Related Questions