我試圖從解析中獲取數據。它有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;
}
意味着,只想要,對具有字符串格式值的字段。 –
你有沒有解決方案? –
@HardikShekhat是的我有解決方案。使用NSDictionary來實現它。 –