Tearing my hair out trying to get the most simple of tutorials to run, from the book 'Head First iPhone Development'
Have a UIPickerView which is bound to an array of objects. That is all. It doesn't do anything, all I want it to do (for now) is to display whats in the array. I've followed the steps in the book word for word, and restarted fresh at least 5 times over. On my latest attempt I've discovered how to debug and added some breakpoints.
This is as far as the app gets
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
if I change that line to return 0; the app loads up with an empty UIPickerView. If it's one, the app bombs out when run.
I've verified the array exists and has data - with pickerview set to 0 components I can return any row off the array to a label. It's only when I wire up the pickerview to the datasource / delegate through the IB that it bombs out.
Really at the end of my tether with this, have been trying to get it to work on and off for weeks and about ready to throw the macbook out the window and hunt down Steve Jobs with a crossbow. I feel especially stupid that it's the first example in the book. Any help would be much appreciated.
UPDATE:
Here's the code
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *) pickerViewnumberOfRowsInComponent :
(NSInteger)component {
return [activities count];
}
- (NSString *)pickerView:(UIPickerView *) titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [activities objectAtIndex:row];
}
I've just tried inserting a space in 'pickerViewnumberOfRowsInComponent', although there is no space in the book. Putting a space in (eg pickerView numberOfRowsInComponent) makes the UIPickerView work, but it's full of question marks instead of the array contents. It does seem like the book has a typo.