多个选择器视图和从Parse检索数据

时间:2015-03-03 15:04:08

标签: ios objective-c parse-platform uipickerview

我在视图控制器中有4个pickerview,我需要在选择了其中2个并具有所需的用户首选项后,我希望第三个根据用户对其他两个选项的选择从Parse检索数据,我能以任何方式实现这个吗?现在我使用标签查看了每个选择器视图,但我无法在pickerview方法中实现PFQuery。

谢谢。

这就是我所拥有的,尝试自定义pickerview但我想使用UIPickerView类方法。

#pragma mark - Select Schedule

-(void)selectSchedule:(NSString *)horari :(NSString *)origen :(NSString *)direccio{
    PFQuery *queryParada = [PFQuery queryWithClassName:@"EixBusParades"];
    [queryParada whereKey:@"Parada" equalTo:origen];
    PFQuery *queryHours = [PFQuery queryWithClassName:@"EixBusParades"];
    [queryHours whereKey:@"hSetmana" equalTo:horari];
    PFQuery *queryDireccio = [PFQuery queryWithClassName:@"EixBusParades"];
    [queryDireccio whereKey:@"direccio" equalTo:direccio];
    PFQuery *querySchedule = [PFQuery orQueryWithSubqueries:@[queryHours,queryParada,queryDireccio]];
    NSArray *objects = [querySchedule findObjects];
    NSArray *depHours = [[objects objectAtIndex:0]objectForKey:@"Horaris"];
    // Copy each object from the array depHours to the pickerview array in order to show it
    /*int i;
    int j = 0;
    for (i = 0; i < [depHours count]; i++) {
        [self.hores objectAtIndex:j] = [depHours objectAtIndex:i];
        j++;
    }*/
}

- (IBAction)tfButton:(id)sender {
    [self.tfHora becomeFirstResponder];
    // Retrieve correct hour data from Parse
    [self selectSchedule:self.tf.text :self.tfOrigen.text :self.tfDireccio.text];
}

- (void)cancelTouched:(UIBarButtonItem *)sender{
    // hide the picker view
    [self.tfHora resignFirstResponder];
}

- (void)doneTouched:(UIBarButtonItem *)sender{
    // hide the picker view
    [self.tfHora resignFirstResponder];
}

在viewdidload中初始化选择器视图。

self.tfHora = [[UITextField alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.tfHora];
    UIPickerView *pickerHora = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    pickerHora.showsSelectionIndicator = YES;
    pickerHora.dataSource = self; // Server
    pickerHora.delegate = self;
    self.tfHora.inputView = pickerHora;

    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    toolBar.barStyle = UIBarStyleBlackOpaque;
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTouched:)];
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelTouched:)];

    // the middle button is to make the Done button align to right
    [toolBar setItems:[NSArray arrayWithObjects:cancelButton, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], doneButton, nil]];
    self.tfHora.inputAccessoryView = toolBar;

0 个答案:

没有答案