我正在尝试使用PFQuery接收的列中的属性加载uipickerview。我想我已经能够成功加载这些项目并使用findObjectsInBackgroundWithBlock方法将它们存储在我的viewDidLoad方法的数组中。 登录到控制台时,数组(查询结果,现在存储在_locationArray中)类似于以下内容
"<Cinema:TWdBNfe6QF:(null)> {\n Location = NY;\n Name = A;\n}",
"<Cinema:uCXICOaQFw:(null)> {\n Location = DC;\n Name = B;\n}",
"<Cinema:TQ1F0Bj5OS:(null)> {\n Location = LA;\n Name = \"A, ICM\";\n}",
"<Cinema:xiUXXYFhAl:(null)> {\n Location = \"San Francisco\";\n Name = C;\n}"
我想在uipickerview中显示位置。
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [_locationArray count];
NSLog(@"%lu", (unsigned long)[_locationArray count]);//It never logs this count
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
// I'm not sure how to get the location attribute
// I get a runtime error if I try to access the _locationArray[row] element
}
请帮忙!提前致谢。
答案 0 :(得分:0)
我要做的是使用for-in循环遍历数组,并创建一个你要添加的新NSMutableArray
。例如:
在标题中:
@property NSMutableArray *stringsArray;//Make sure to init in viewDidLoad
在.m:
for(PFObject *object in _locationArray)
{
[self.stringsArray addObject:[object objectForKey:@"Location"]];
}
然后:
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [self.stringsArray objectAtIndex:row];
}