界面生成器连接导致选项卡栏应用程序崩溃

发布于 2024-11-28 05:16:21 字数 1086 浏览 2 评论 0原文

为了练习,我尝试从头开始开发一个基于选项卡栏的简单 iPhone 应用程序,但我遇到了一些问题.. 我已按照以下步骤进行操作: http://www.techotopia.com/index.php/Creating_an_iPhone_Multiview_Application_using_the_Tab_Bar

应用程序正确加载三个视图,直到内部没有连接为止;如果我将任何插座或操作连接到子视图的标签或按钮,应用程序就会崩溃。

例如,我的firstView.h包含:

#import <UIKit/UIKit.h>


@interface firstView : UIViewController {
IBOutlet UILabel *resultLabel;
}

-(IBAction)randomizeAction;

@property (nonatomic , retain) IBOutlet UILabel *resultLabel;


@end

和firstView.m

-(IBAction)randomizeAction:(id)sender
{
//NSInteger rand = arc4random() % 75;
//resultLabel.text = [ [NSString alloc] initWithFormat:@"Random integer: @%",rand];
UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"Yeah!" message:@"Yeah" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil ];
[alert show];
[alert release];

}

如果我将标签连接到resultOutlet或将按钮连接到“randomizeAction”方法,则当我切换到相关视图时应用程序崩溃。 错误在哪里?

for exercise I'm trying to develop a simple iPhone application based on a tab bar from scratch, but I had some problem..
I've follow up these steps: http://www.techotopia.com/index.php/Creating_an_iPhone_Multiview_Application_using_the_Tab_Bar

The app loads correctly the three views until there's no connection within; if I connect any outlets or action to a label or button of the subviews, the app crash.

For example, my firstView.h contains:

#import <UIKit/UIKit.h>


@interface firstView : UIViewController {
IBOutlet UILabel *resultLabel;
}

-(IBAction)randomizeAction;

@property (nonatomic , retain) IBOutlet UILabel *resultLabel;


@end

and the firstView.m

-(IBAction)randomizeAction:(id)sender
{
//NSInteger rand = arc4random() % 75;
//resultLabel.text = [ [NSString alloc] initWithFormat:@"Random integer: @%",rand];
UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"Yeah!" message:@"Yeah" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil ];
[alert show];
[alert release];

}

If I connect a label to the resultOutlet or a button to the "randomizeAction" method, the app crash when I switch to the related views..
Where is the mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Smile简单爱 2024-12-05 05:16:21

在 .h 文件中,您将属性声明为 IBOutlet 两次。因为我不认为这会导致问题,但这是不必要的。此外,您还在 .h 文件中声明了没有参数的 randomizeAction,并使用参数实现了它。

您的代码应如下所示:

#import <UIKit/UIKit.h>

@interface firstView : UIViewController {
   UILabel *resultLabel;
}
@property (nonatomic , retain) IBOutlet UILabel *resultLabel;

-(IBAction)randomizeAction:(id)sender;

@end

和firstView.m

-(IBAction)randomizeAction:(id)sender
{
   //do stuff
}

in .h file you declare a property to be IBOutlet twice. As I don't think this causes the problem but it's just unnecessary. Also you declared randomizeAction in the .h file wihout the parameter and you implemented it with a parameter.

Your code should look like this:

#import <UIKit/UIKit.h>

@interface firstView : UIViewController {
   UILabel *resultLabel;
}
@property (nonatomic , retain) IBOutlet UILabel *resultLabel;

-(IBAction)randomizeAction:(id)sender;

@end

and the firstView.m

-(IBAction)randomizeAction:(id)sender
{
   //do stuff
}
信仰 2024-12-05 05:16:21

从该错误消息看来,您的视图控制器未在 Interface Builder 中正确连接。您确定您的视图控制器(IB 中的文件所有者)被识别为firstView 的实例吗?在 XCode 的 Identity Inspector 中检查它是什么类。

此外,如果您可以显示声明和创建视图控制器的代码(最有可能在应用程序委托中),这也会很有帮助。

From that error message it looks like your view controller isn't hooked up properly in Interface Builder. Are you sure your view controller (File's Owner in IB) is identified as an instance of firstView? Check what class it is in the Identity Inspector in XCode.

Also it would be helpful if you can show the code where your view controller is declared and created (most likely in the App Delegate).

萌辣 2024-12-05 05:16:21

我不确定,但我认为你必须改变这一点

@interface DetailViewController : UIViewController

@interface firstView : UIViewController

I'm not sure, but I think you have to change this:

@interface DetailViewController : UIViewController

To:

@interface firstView : UIViewController
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文