user1550951
user1550951

Reputation: 379

Close UIViewController on button click

I am opening a viewcontroller(with a navigation bar and a bar button item for closing the view controller).This is view controller is for displaying information to the user when he clicks on a 'Help' button.The navigation is like this: ViewController1 -> "Help" button -> Viewcontroller2. The Viewcontroller2 has a "Close" button which dismisses this ViewController. I have the Close button with an IBAction hooked to the File's owner.But the break-point is not hit when I click the 'close' button. The code is:

DetailViewController.m(viewcontroller1):

-(void) showHelp:(id)sender
{
    HelpViewController *helpWindow = [[HelpViewController alloc]initWithNibName:@"HelpViewController" bundle:[NSBundle mainBundle]];
    helpWindow.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:helpWindow animated:YES];
}

HelpViewController.m(viewcontroller2):

#import "HelpViewController.h"

@interface HelpViewController ()

@end

@implementation HelpViewController

@synthesize scrollView;


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

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)closeAction:(id)sender {
    [self dismissModalViewControllerAnimated:YES];

}

@end

I tried putting a breakpoint at "closeAction" but it isn't hit. I am new to iOS development.I am missing something very obvious here.Any help is appreciated!

Upvotes: 0

Views: 1286

Answers (1)

Dinesh Raja
Dinesh Raja

Reputation: 8501

Click your Close button and select connection inspector tab in the right side tools. Check your button is connected with closeAction: this method in touchUpInside mode.

If not, then connect your UIButton outlet to this method -(IBAction)closeAction:(id)sender; and then try.

UPDATE: if your button is UIBarButtonItem, then there will be an option as "New referencing outlet". drag from that and connect with your method.

Upvotes: 1

Related Questions