Question

What I want to do is have both UISegmentedControl boxes set the itemCondition and itemLocation object properties to their respective values, depending on which button is pressed.

This value will then be sent over to a Parse cloud code function as a parameter, as seen in the submitButton function. I know that with minPrice and maxPrice for example, those are user provided values, so you can send over self.minPrice.text as the param.

Setting the UISegmentedControl to self.itemCondition and sending that as a param doesn't seem to be working however. Since the segmented button is what sets the value, rather than the user explicitly typing something into a text box, I assume it is done differently, I'm just not sure how.

This is the code from my criteriaViewController that handles everything mentioned.

- (IBAction)conditionToggle:(id)sender{

    if(Segment.selectedSegmentIndex == 0){
        self.itemCondition == 'new';
    }
    else if(Segment.selectedSegmentIndex == 1){
        self.itemCondition == 'any';
    }

}

- (IBAction)itemLocationToggle:(id)sender {

    if(Segment.selectedSegmentIndex == 0){
        self.itemLocation == 'US';
    }
    else if(Segment.selectedSegmentIndex == 1){
        self.itemLocation == 'WorldWide';
    }
}

- (IBAction)submitButton:(id)sender
{
    if (self.itemSearch.text.length > 0) {

        //add all the info to users respective category object


        //perform search with criteria just submitted
        [PFCloud callFunctionInBackground:@"eBayCriteriaSearch"
                           withParameters:@{@"item": self.itemSearch.text,
                                            @"minPrice": self.minPrice.text,
                                            @"maxPrice": self.maxPrice.text,
                                            @"itemCondition": self.itemCondition,
                                            @"itemLocation": self.itemLocation,}
                                    block:^(NSString *result, NSError *error) {

                                        if (!error) {
                                            NSLog(@"The result is '%@'", result);

                                            if ([result intValue] == 1) {
                                                [self performSegueWithIdentifier:@"ShowMatchCenterSegue" sender:self];
                                            } else {
                                                [self performSegueWithIdentifier:@"ShowCriteriaSegue" sender:self];
                                            }

                                        }
                                    }];
    }
}
Was it helpful?

Solution

You have a double equals in your assignment to self.itemCondition. That's a comparison operator. You need to use just '=' to assign a value.

Also, if itemCondition is an NSString, then you need to change the syntax for each assignment so it looks like this:

self.itemCondition = @"new";

Note the @ and double quotes.

Also, I'd probably use a switch statement instead of several else if statements since you may have more segments in the future. So here's how the event method for your itemCondition segmented control would look for me.

- (IBAction)mySegmentedControl_ValueChanged:(id)sender {

    switch (self.mySegmentedControl.selectedSegmentIndex) {

        default:
        case 0:
            self.itemCondition = @"new";
            break;

        case 1:
            self.itemCondition = @"any";
            break;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top