Displaying modal view in Objective-C

Posted by kpower on Stack Overflow See other posts from Stack Overflow or by kpower
Published on 2010-04-06T04:17:37Z Indexed on 2010/04/06 4:23 UTC
Read the original article Hit count: 219

Filed under:
|
|

I'm trying to display Modal View in my app.

I have subclass of UIViewController that has only the "Done" button (UIButton created with IB and linked with XCode).

.h

@interface myModalVC : UIViewController {
    UIButton *bDone;
}

@property (nonatomic, retain) IBOutlet UIButton *bDone;

- (IBAction)bDoneTouchDown:(id)sender;

@end

.m

#import "myModalVC.h"    

@implementation myModalVC

@synthesize bDone;

- (void)dealloc {
    [bDone release];
    [super dealloc];
}

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

- (void)viewDidUnload {
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (UIInterfaceOrientationLandscapeLeft == interfaceOrientation
                || UIInterfaceOrientationLandscapeRight == interfaceOrientation);
}

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

- (IBAction)bDoneTouchDown:(id)sender {
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

@end

I'm trying to display modal view with this code (from my main view):

myModalVC *temp = [[[myModalVC alloc]
            initWithNibName:@"myModalVC" bundle:[NSBundle mainBundle]] autorelease];
[self presentModalViewController:temp animated:YES];

If this code is placed in some method, that responds to button touches - everything is fine. But when I place it to some other method (called during some processes in my app) - modal view is displayed without problems, but when I press (touch) "Done" button, application crashes with "Program received signal: “EXC_BAD_ACCESS”."

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c