Ho seguito un paio di tutorial su youtube oltre a consigli su questo aspetto, ma non riesco a ottenere che UIPickerView visualizzi i suoi dati. Sto compilando il raccoglitore usando tre array e ho pensato di aver implementato il codice correttamente, ma ovviamente qualcosa non va. Il selettore mostra correttamente il numero di elementi, il problema è che sono tutti visualizzati come '?'UIPickerView non visualizza dati
Ho provato a impostare autonomamente il delegato del raccoglitore, ma anche questo non ha funzionato. Grazie in anticipo.
Ecco il mio file h:
@interface BACcalcViewController : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate>
@property(strong, nonatomic) IBOutlet UIPickerView *personInfoPicker;
@property(strong, nonatomic) NSArray *heightsArray;
@property(strong, nonatomic) NSArray *weightsArray;
@property(strong, nonatomic) NSArray *timeArray;
@end
Ecco il mio file .m:
@interface BACcalcViewController() <UIPickerViewDataSource, UIPickerViewDelegate>
@end
@implementation BACcalcViewController
@synthesize personInfoPicker, heightsArray, weightsArray, timeArray;
- (void)viewDidLoad
{
[super viewDidLoad];
heightsArray = [NSArray arrayWithObjects:
@"5ft 0in",
@"5ft 1in",
@"5ft 2in",
@"5ft 3in",
@"5ft 4in",
@"5ft 5in",
@"5ft 6in",
@"5ft 7in",
@"5ft 8in",
@"5ft 9in",
@"5ft 10in",
@"5ft 11in",
@"6ft 1in",
@"6ft 2in",
@"6ft 3in",
@"6ft 4in",
@"6ft 5in",
@"6ft 6in",
@"6ft 7in",
@"6ft 8in",
nil];
weightsArray = [NSArray arrayWithObjects:
@"100",
@"110",
@"120",
@"130",
@"140",
@"150",
@"160",
@"170",
@"180",
@"190",
@"200",
@"210",
@"220",
@"230",
@"240",
@"250",
@"260",
nil];
timeArray = [NSArray arrayWithObjects:
@"1",
@"2",
@"3",
@"4",
@"5",
@"6",
nil];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)personInfoPicker
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)personInfoPicker numberOfRowsInComponent: (NSInteger)component
{
if (component == 0)
return [heightsArray count];
else if (component == 1)
return [weightsArray count];
else
return [timeArray count];
}
- (NSString *)pickerview:(UIPickerView *)personInfoPicker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == 0)
return [heightsArray objectAtIndex:row];
else if (component == 1)
return [weightsArray objectAtIndex:row];
else
return [timeArray objectAtIndex:row];
}
@end
hai impostato il delegato e l'origine dati di UIPickerView su File Owner? – channi
Sì, ho collegato tutte le parti IB nello storyboard proprio come i video di YouTube. – theJPE
quindi prova la risposta @ Durgaprasad una volta che può essere d'aiuto – channi