我想要做的是让两个UISegmentedControl框将itemCondition和itemLocation对象属性设置为各自的值,具体取决于按下的按钮。
然后将该值作为参数发送到Parse云代码函数,如submitButton
函数中所示。我知道使用minPrice和maxPrice,这些是用户提供的值,因此您可以通过self.minPrice.text作为参数发送。
将UISegmentedControl设置为self.itemCondition并将其作为参数发送似乎并不起作用。由于分段按钮是设置值的,而不是用户明确地在文本框中输入内容,我认为它是以不同的方式完成的,我只是不确定如何。
这是我的criteriaViewController中处理所有内容的代码。
- (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];
}
}
}];
}
}
答案 0 :(得分:0)
你在self.itemCondition的任务中有一个双等于。那是一个比较运算符。您只需使用'='来分配值。
另外,如果itemCondition是NSString,那么您需要更改每个赋值的语法,使其如下所示:
self.itemCondition = @“new”;
注意@和双引号。
此外,我可能会使用switch语句而不是其他几个if语句,因为将来可能会有更多段。所以这里是你的itemCondition分段控件的事件方法将如何找我。
- (IBAction)mySegmentedControl_ValueChanged:(id)sender {
switch (self.mySegmentedControl.selectedSegmentIndex) {
default:
case 0:
self.itemCondition = @"new";
break;
case 1:
self.itemCondition = @"any";
break;
}
}