Shrey
Shrey

Reputation: 1977

switch between xibs on button action

I'm having difficulty in switching between xibs :(

first i was using navigationController and it worked well but i want to do it without using navigationController.

I tried presentModalViewController but it crashes my application. :((

Here is the code :

    myViewController *viewController = [myViewController alloc] initWithNibName:nil bundle:nil];
    myViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController: myViewController animated:YES];
    [myViewController release];

It is not working, ERROR received : GDB:Program received signal : "EXC_BAD_ACCESS"

Upvotes: 1

Views: 413

Answers (4)

Kasaname
Kasaname

Reputation: 1501

Don't release he controller its a global variable i suppose so just make it in nil in dealloc

Upvotes: 0

iPhone fan
iPhone fan

Reputation: 26

myViewController *viewController = [myViewController alloc] initWithNibName:nil bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController: viewController animated:YES];

this should work. your problem was that you declared a view controller and named it "viewController", but you were not using that. you were using the view controllers name, not the declared instance.

Upvotes: 1

Atulkumar V. Jain
Atulkumar V. Jain

Reputation: 5098

remove the release statement from ur code and everything will work fine.

Actually u r releasing the viewcontroller before it is shown as the superview.

//[myViewController release];

Hope this helps u...

Upvotes: 0

Ajith
Ajith

Reputation: 1457

You have set your nibName to nil Enter the name of your Xib file you want to display there Like

 myViewController *viewController = [[myViewController alloc] initWithNibName:@"nameOfYourXIB" bundle:nil]autorelease];
    myViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController: myViewController animated:YES];

Upvotes: 0

Related Questions