开发者

Crash in the simulator when i try to go to an other view

开发者 https://www.devze.com 2023-03-26 11:39 出处:网络
so I have a tab bar application where i have put a button to go to an other view. so in the FirstView.h 开发者_如何学编程i have that

so I have a tab bar application where i have put a button to go to an other view.

so in the FirstView.h 开发者_如何学编程i have that

IBOutlet ContactMainViewController *contactMainViewController;

and that

-(IBAction)gotoContactMainViewController;

in my FirstView.m i have

-(IBAction)gotoContactMainViewController {

    [self presentModalViewController:contactMainViewController animated:YES];
}

and in my SecondView that i have created in the .h

-(IBAction)goBack;

and in the .m

-(IBAction)goBack {

    [self dismissModalViewControllerAnimated:YES];
}

The app run correctly but when i click on the button, a green line come over

[self presentModalViewController:contactMainViewController animated:YES];

and say "Thread 1: Program received signal: "SIGABRT" and this in the console: terminate called throwing an exception[Switching to process 3908 thread 0xb303]

Thanks for your help !


What kind of FirstView and ContactMainViewController class file? is it a UIViewController or simple UIView? we assume that ContactMainViewController is a separate class file

in your firstView.m

#import "ContactMainViewController.h"

-(IBAction)gotoContactMainViewController {

    ContactMainViewController _contactMainVC = [[ContactMainViewController alloc]init];

    [self presentModalViewController:_contactMainVC animated:YES];
    [_contactMainVC release];
}

Add the @class ContactMainViewController; in the header before the @interface. That should do it. Also be sure to #import "ContactMainViewController.h" in your .m file to avoid warnings


You must add the code provided by Legolas just before:

[self presentModalViewController:contactMainViewController animated:YES];


You need to allocate contactMainViewController before pushing views.

-(IBAction)gotoContactMainViewController {


if (self.contactMainViewController == nil)
  self.contactMainViewController = [[ContactMainViewController alloc] init];

[self presentModalViewController:contactMainViewController animated:YES];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消