我试图从解析中获取数据。字符串格式有4-5个字段,并在IOS故事板的下拉菜单中显示。
实际上有9列包括解析默认列。他们创建数据,ACL,对象ID等等。
我只需从解析中获取字符串格式的字段,并希望将它们显示为UIViewController中的下拉菜单。用于下拉我是UITableViewController。 serviceview.h
@interface ServiceViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic)NSArray *selectionArray;
@property (weak, nonatomic) IBOutlet UILabel *resultLabel;
@property (weak, nonatomic) IBOutlet UIPickerView *servicepicker;
@property (weak, nonatomic) IBOutlet UITableView *tableViewCars;
@property (strong, nonatomic)NSArray *customerCars;
- (IBAction)customerCarBtn:(id)sender;
serviceview.m
@interface ServiceViewController ()
@end
@implementation ServiceViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableViewCars.delegate = self;
self.tableViewCars.dataSource = self;
_selectionArray = @[@"Car Service", @"Brake Pads", @"Car Battery", @"Alternator",@"Starter Motor",@"Timing Belt",@"Cooling System",@"Clutch Repair",@"Repair-Others"];
NSString *uType = [[PFUser currentUser] objectForKey:@"email"];
PFQuery *query = [PFQuery queryWithClassName:@"customerCars"];
[query whereKey:@"cEmail" containsString:uType];
NSLog(@"%@",uType);
[query findObjectsInBackgroundWithBlock:^(NSArray *customerCar, NSError *error) {
if (customerCar) {
NSLog(@"Successfully retrieved %lu scores.", (unsigned long)customerCar.count);
for (PFObject *objects in customerCar) {
NSLog(@"%@", objects.objectId);
_customerCars = @[objects];
self.customerCars = [[NSArray alloc]initWithObjects:@[objects], nil];
// NSLog(@"%@",[_customerCars.objectId]);
}
//NSLog(customerCars);
}
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.customerCars count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [self.customerCars objectAtIndex:indexPath.row] ;
//cell.textLabel.font = [UIFont systemFontOfSize:11.0];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self.tableViewCars cellForRowAtIndexPath:indexPath];
self.tableViewCars.hidden = YES;
}
- (IBAction)customerCarBtn:(id)sender {
if (self.tableViewCars.hidden == YES) {
self.tableViewCars.hidden = NO;
}
else
self.tableViewCars.hidden = YES;
}
答案 0 :(得分:0)
存储在customerCars
数组中的对象属于PFObject
类型,因为这是Parse返回的内容。
为了从汽车的某个Parse属性中获取String值,请将其作为对象上的字典键进行访问。
例如,假设您要更新单元格文本标签以显示汽车的“颜色”属性。你会使用类似的东西:
PFObject *car = [self.customerCars objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat: @"%@ - %@", car[@"make"], car[@"model"]];
答案 1 :(得分:0)
首先,您必须检查具有字符串格式值的字段的解析。
然后你必须使用PFQuery的selectKeys方法并在数组中传递keyNames来从解析中仅获取选定的键,如下所示:
PFQuery *query = [PFQuery queryWithClassName:@"customerCars"];
[query whereKey:@"cEmail" containsString:uType];
[query selectKeys:@[@"column1",@"column2",@"column3"]];