Я хочу, чтобы оба поля UISegmentedControl устанавливали свойства объекта itemCondition и itemLocation в соответствующие значения в зависимости от того, какая кнопка нажата.
Затем это значение будет отправлено в функцию облачного кода Parse в качестве параметра, как показано в функции submitButton. Я знаю, что, например, с minPrice и maxPrice это значения, предоставляемые пользователем, поэтому вы можете отправить self.minPrice.text в качестве параметра.
Однако установка UISegmentedControl на self.itemCondition и отправка его в качестве параметра, похоже, не работает. Поскольку сегментированная кнопка устанавливает значение, а не пользователь явно вводит что-то в текстовое поле, я предполагаю, что это делается по-другому, я просто не уверен, как это сделать.
Это код из моего критерияViewController, который обрабатывает все упомянутое.
- (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];
}
}
}];
}
}