点击按钮时,解析云代码不会运行

时间:2014-05-11 18:59:44

标签: javascript objective-c parse-platform

我已将代码设置为在Parse后端运行云代码,但是,点击提交按钮似乎不会启动该功能。我认为问题在于将操作连接到提交按钮或Parse代码。

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

云代码功能:

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');
      }

    });





});

1 个答案:

答案 0 :(得分:1)

看起来你没有正确启动你的Parse对象。它应该这样做:

var UserCategory = Parse.Object.extend("userCategory")
var newUserCategory = new UserCategory()
...

您是否检查了云代码日志中的错误消息?调试云代码的最佳方法是将console.log()消息放入云代码中,然后检查这些消息的云代码日志。我有时会使用console.log("步骤1")然后"步骤2"等...来查看代码在哪里失败。我还在console.log中使用JSON.stringify()来查看对象。调试云代码可能很痛苦。