I have my code set up to run cloud code on Parse backend, however, tapping the submit button doesn't seem to initiate the function. I think the issue is either in connecting the action to the submit button, or to the Parse code.
CriteriaViewController.m:
#import "CriteriaViewController.h"
@interface CriteriaViewController ()
@property (weak, nonatomic) IBOutlet UISegmentedControl *itemConditionSegment;
@property (weak, nonatomic) IBOutlet UISegmentedControl *itemLocationSegment;
@property (weak, nonatomic) IBOutlet UIButton *submitButton;
@end
@implementation CriteriaViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)itemConditionSegment:(id)sender{
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
self.itemCondition = @"new";
}
else{
self.itemCondition = @"any";
}
}
- (IBAction)itemLocationSegment:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
self.itemLocation = @"US";
}
else if (selectedSegment == 1) {
self.itemLocation = @"WorldWide";
}
}
//add all the info to users respective new category object
- (IBAction)submitButton:(id)sender
{
if (self.minPrice.text.length > 0 && self.maxPrice.text.length > 0)
{
[PFCloud callFunctionInBackground:@"userCategorySave"
withParameters:@{@"categoryId": self.chosenCategory,
@"minPrice": self.minPrice.text,
@"maxPrice": self.maxPrice.text,
@"itemCondition": self.itemCondition,
@"itemLocation": self.itemLocation,}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"Criteria successfuly saved.");
[self performSegueWithIdentifier:@"ShowMatchCenterSegue" sender:self];
}
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
@end
Cloud code function:
Parse.Cloud.define("userCategorySave", function(request, response) {
var newUserCategory = new userCategory();
newUserCategory.set("categoryId", request.params.categoryId);
newUserCategory.set("minPrice", request.params.minPrice);
newUserCategory.set("maxPrice", request.params.maxPrice);
newUserCategory.set("itemCondition", request.params.itemCondition);
newUserCategory.set("itemLocation", request.params.itemLocation);
newUserCategory.set("parent", Parse.User.current());
newUserCategory.save({
success: function (){
console.log ('userCategory successfully created!');
response.success('Request successful');
},
error: function (){
console.log('error!!!');
response.error('Request failed');
}
});
});