将对象从解析转换为数组并转换为字符串

时间:2021-10-02 21:14:47

I'm trying to fetch data from parse. that have 4-5 fields in string format and display them in the dropdown menu of IOS storyboard.

我正在尝试从解析中获取数据。字符串格式有4-5个字段,并在IOS故事板的下拉菜单中显示。

there are actually 9 columns including parse default columns. they create data,ACL, Object ID so and so forth.

实际上有9列包括解析默认列。他们创建数据,ACL,对象ID等等。

I'm need to fetch only those fields from parse which are in string format and i want display them as a dropdown menu in UIViewController. for dropdown i'm UITableViewController. serviceview.h

我需要只从字符串格式的parse中获取那些字段,并且我希望将它们显示为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;


}

2 个解决方案

#1


0  

The objects being stored in your customerCars array, are of type PFObject, because that is what Parse returns.

存储在customerCars数组中的对象属于PFObject类型,因为这是Parse返回的对象。

In order to obtain the String value from one of your Parse properties of a car, access it as a dictionary key on the object.

要从汽车的某个Parse属性中获取String值,请将其作为对象上的字典键进行访问。

For example, say you wanted to update the cell text label to display the 'colour' property of a car. You would use something like:

例如,假设您要更新单元格文本标签以显示汽车的“颜色”属性。你会使用类似的东西:

PFObject *car = [self.customerCars objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat: @"%@ - %@", car[@"make"], car[@"model"]];

#2


0  

First you have to check on parse for field that have values in string format.

首先,您必须检查具有字符串格式值的字段的解析。

Then you have to use PFQuery's selectKeys method and pass keyNames in array to fetch only selected Keys from parse like this :

然后你必须使用PFQuery的selectKeys方法并在数组中传递keyNames来从解析中仅获取选定的键,如下所示:

PFQuery *query = [PFQuery queryWithClassName:@"customerCars"];
[query whereKey:@"cEmail" containsString:uType];
[query selectKeys:@[@"column1",@"column2",@"column3"]];

#1


0  

The objects being stored in your customerCars array, are of type PFObject, because that is what Parse returns.

存储在customerCars数组中的对象属于PFObject类型,因为这是Parse返回的对象。

In order to obtain the String value from one of your Parse properties of a car, access it as a dictionary key on the object.

要从汽车的某个Parse属性中获取String值,请将其作为对象上的字典键进行访问。

For example, say you wanted to update the cell text label to display the 'colour' property of a car. You would use something like:

例如,假设您要更新单元格文本标签以显示汽车的“颜色”属性。你会使用类似的东西:

PFObject *car = [self.customerCars objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat: @"%@ - %@", car[@"make"], car[@"model"]];

#2


0  

First you have to check on parse for field that have values in string format.

首先,您必须检查具有字符串格式值的字段的解析。

Then you have to use PFQuery's selectKeys method and pass keyNames in array to fetch only selected Keys from parse like this :

然后你必须使用PFQuery的selectKeys方法并在数组中传递keyNames来从解析中仅获取选定的键,如下所示:

PFQuery *query = [PFQuery queryWithClassName:@"customerCars"];
[query whereKey:@"cEmail" containsString:uType];
[query selectKeys:@[@"column1",@"column2",@"column3"]];