Question

I want the code in - (IBAction)nextButton:(id)sender to run when I click my next button, however clicking it doesn't seem to register.

I made sure the nextButton was connected to the parent controller (SearchViewController), and I have two segues leading to the two secondary view controllers.

The view controller it segues to depends on the value returned by the function.

I'm thinking that the problem is either in how I structured the function, or how I laid out the segues.

#import "SearchViewController.h"

@interface SearchViewController ()
@property (weak, nonatomic) IBOutlet UITextField *itemSearch;
@property (weak, nonatomic) IBOutlet UIButton *nextButton;

@end

@implementation SearchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (IBAction)nextButton:(id)sender
{
    if (self.itemSearch.text.length > 0) {
        [PFCloud callFunctionInBackground:@"eBayCategorySearch"
                           withParameters:@{@"item": self.itemSearch.text}
                                    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];
                                            }
                                        }
                                    }];
    }
}

enter image description here

Was it helpful?

Solution

The only issue I can think of is that while the button maybe connected to searchViewController, - (IBAction)nextButton:(id)sender may not be assigned to the button. Try this in searchViewController: First, in its header file, add nextButtonOutlet as an IBOutlet. Then in the .m file, write

[self.nextButtonOutlet addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];

See if this works.

Edit: write that line of code in viewDidLoad method.

OTHER TIPS

Try this...

Step 1: Create IBOutlet for button

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.nextButtonOutlet addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];    
}

Step 2: Button Action

- (IBAction)nextButton:(id)sender
{
    NSLog(@"Button Clicked");
    //-- Your code implementation
}

Disconnect the segue from the button itself and make the connection between the two ViewControllers. Also, give the segue itself an identifier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top