0

所以我有一个标签栏应用程序,我在其中放置了一个按钮以转到另一个视图。

所以在 FirstView.hi 中有那个

IBOutlet ContactMainViewController *contactMainViewController;

然后

-(IBAction)gotoContactMainViewController;

在我的 FirstView.mi 中有

-(IBAction)gotoContactMainViewController {

    [self presentModalViewController:contactMainViewController animated:YES];
}

在我在 .h 中创建的 SecondView 中

-(IBAction)goBack;

在.m

-(IBAction)goBack {

    [self dismissModalViewControllerAnimated:YES];
}

该应用程序运行正常,但是当我单击按钮时,出现一条绿线

[self presentModalViewController:contactMainViewController animated:YES];

"Thread 1: Program received signal: "SIGABRT" 在控制台中说: terminate called throwing an exception[Switching to process 3908 thread 0xb303]

谢谢你的帮助 !

4

3 回答 3

1

您必须在之前添加 Legolas 提供的代码:

[self presentModalViewController:contactMainViewController animated:YES];
于 2011-08-04T17:59:36.360 回答
1

什么样的 FirstView 和 ContactMainViewController 类文件?它是 UIViewController 还是简单的 UIView?我们假设 ContactMainViewController 是一个单独的类文件

在你的 firstView.m

#import "ContactMainViewController.h"

-(IBAction)gotoContactMainViewController {

    ContactMainViewController _contactMainVC = [[ContactMainViewController alloc]init];

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

添加@class ContactMainViewController;在@interface 之前的标题中。那应该这样做。还要确保在您的 .m 文件中 #import "ContactMainViewController.h" 以避免出现警告

于 2011-08-04T18:04:58.137 回答
0

您需要contactMainViewController在推送视图之前进行分配。

-(IBAction)gotoContactMainViewController {


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

[self presentModalViewController:contactMainViewController animated:YES];
}
于 2011-08-04T17:26:28.813 回答