2014-05-11 1 views
1

코드를 파스 (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

것 같습니다. 다음과 같이 수행해야합니다.

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

오류 코드에 대한 클라우드 코드 로그를 확인 했습니까? 클라우드 코드를 디버깅하는 가장 좋은 방법은 클라우드 코드에 console.log() 메시지를 넣은 다음 해당 메시지에 대한 클라우드 코드 로그를 확인하는 것입니다. 나는 때때로 console.log ("1 단계")와 "2 단계"등을 사용하여 코드에서 오류가 발생한 부분을 확인합니다. 또한 JSON.stringify()를 사용하여 console.log에서 객체를 볼 수 있습니다. 클라우드 코드 디버깅은 어려울 수 있습니다.

관련 문제