Hi I’m quite new to coding for iOs and can’t get this to work. I try to make the label of a button change based on the array item of the PickerView that is selected.
(void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *buttonLable = [_characters objectAtIndex:[pickerView selectedRowInComponent:0]];
[titleButton setTitle:(NSString *)buttonLable forState:UIControlStateNormal];
}
I think it has a problem with how I defined buttonLable as it says “@variable is not NSString”.
What am I doing wrong?
Thank you!
Your code is syntactically correct, and your error message is thus output when you run the code.
The reason is the content of your array
_characters. Since you can only assign an NSString object tobuttonLable, the array element stored at index[pickerView selectedRowInComponent:0]has some other class. Just set a breakpoint at the assign statement an look for this class.