问题描述
|
我在这里搜索,但没有看到类似此错误的信息。
我正在尝试在ViewDidLoad上填充我的pickerview,但是当我运行程序时,pickerView只是填充了\“?\”而不是我的字符串...这是怎么回事?提前致谢。
- (void)viewDidLoad {
[super viewDidLoad];
activities = [[NSArray alloc] initWithObjects:@\"sleeping\",@\"eating\",@\"working\",@\"thinking\",@\"crying\",@\"begging\",@\"leaving\",@\"shopping\",@\"hello worlding\",nil];
feelings = [[NSArray alloc] initWithObjects:@\"awsome\",@\"sad\",@\"happy\",@\"ambivalent\",@\"nauseous\",@\"psyched\",@\"confused\",@\"hopeful\",@\"anxious\",nil];
}
解决方法
您需要实现
UIPickerViewDelegate
和UIPickerViewDataSource
协议:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0)
return [activities count];
else
return [feelings count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == 0)
return [activities objectAtIndex:row];
else
return [feelings objectAtIndex:row];
}