我有一个包含电影和演员数组的模型对象。我正在尝试在同一个 ViewController 中填充 2 个选择器(1 个带有电影的选择器,另一个带有演员的选择器)。请帮忙,因为我仍在学习它是如何工作的。
谢谢!
我的代码如下...
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.model = [[MovieModel alloc] init];
for(int i = 0; i < self.model.count; i++){
NSString *movies = [self.model movieForIndex:i];
NSLog(@" Movie = %@", movies);
}
for(int i = 0; i < self.model.count; i++){
NSString *actors = [self.model actorForIndex:i];
NSLog(@" Actor = %@", actors);
}
}
//这是我遇到问题的地方。谢谢!!!
#pragma mark - Picker View Delegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0){
return [self.model movieForIndex: row];
}
else if (component == 1){
return [self.model actorForIndex: row];
}
else
return nil;
}
#pragma mark - Picker View Data Source
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return self.model.count;
}
@end