[英]Populate UIPickerView with PFQuery
我正在嘗試使用通過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
}
請幫忙! 提前致謝。
我要做的是使用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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.