界面生成器连接导致选项卡栏应用程序崩溃
为了练习,我尝试从头开始开发一个基于选项卡栏的简单 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 .h 文件中,您将属性声明为 IBOutlet 两次。因为我不认为这会导致问题,但这是不必要的。此外,您还在 .h 文件中声明了没有参数的 randomizeAction,并使用参数实现了它。
您的代码应如下所示:
和firstView.m
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:
and the firstView.m
从该错误消息看来,您的视图控制器未在 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).
我不确定,但我认为你必须改变这一点
:
I'm not sure, but I think you have to change this:
To: