views:

145

answers:

1

I had used the below code to get the row index of the picker view with two components. But there is two warnings saying "Local declaration of pickerView 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);

}

A: 

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);
glorifiedHacker
It worked!! Thanks a lot!!!
iSharreth