Objective c 未声明的SubViewTwoController(此函数首次使用)(obj-c)
大家好:) 是一个链接列表。你在读这篇文章时需要它 我是Objective-C的新手,尝试学习它来开发iPhone应用程序。我使用链接列表中链接的教程创建了一个带有简单基本导航的标准应用程序。 此应用程序包含启动时显示的“RootView”。启动屏幕本身包含三个元素,它们都链接到SubViewOne。 到目前为止,我都能做到这一点。 因此,我要更改的是使第二个元素链接到SubViewTwo 当我“构建并运行”它时,会出现以下错误: RootViewController.m:Objective c 未声明的SubViewTwoController(此函数首次使用)(obj-c),objective-c,iphone,cocoa-touch,Objective C,Iphone,Cocoa Touch,大家好:) 是一个链接列表。你在读这篇文章时需要它 我是Objective-C的新手,尝试学习它来开发iPhone应用程序。我使用链接列表中链接的教程创建了一个带有简单基本导航的标准应用程序。 此应用程序包含启动时显示的“RootView”。启动屏幕本身包含三个元素,它们都链接到SubViewOne。 到目前为止,我都能做到这一点。 因此,我要更改的是使第二个元素链接到SubViewTwo 当我“构建并运行”它时,会出现以下错误: RootViewController.m: SubViewTwo
SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init];
//未声明的SubViewTwoController(首次在此函数中使用)
在subviewtowcontroller.m中
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
在@interface中没有为“SubViewTwoController”声明超类
之后也是一样
- (void)dealloc {
[super dealloc];
我想你也需要头文件,所以他们在这里
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
IBOutlet NSMutableArray *views;
}
@property (nonatomic, retain) IBOutlet NSMutableArray *views;
@end
#import <UIKit/UIKit.h>
@interface SubViewOneController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIButton *button;
}
@property (retain,nonatomic) IBOutlet UILabel *label;
@property (retain,nonatomic) IBOutlet UIButton *button;
- (IBAction) OnButtonClick:(id) sender;
@end
#import <UIKit/UIKit.h>
@interface SubViewTwo : UIViewController {
IBOutlet NSMutableArray *views;
}
@end
#导入
@接口RootViewController:UITableViewController{
IBNSmutableArray*视图;
}
@属性(非原子,保留)IBNSMutableArray*视图;
@结束
SubViewOneController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
IBOutlet NSMutableArray *views;
}
@property (nonatomic, retain) IBOutlet NSMutableArray *views;
@end
#import <UIKit/UIKit.h>
@interface SubViewOneController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIButton *button;
}
@property (retain,nonatomic) IBOutlet UILabel *label;
@property (retain,nonatomic) IBOutlet UIButton *button;
- (IBAction) OnButtonClick:(id) sender;
@end
#import <UIKit/UIKit.h>
@interface SubViewTwo : UIViewController {
IBOutlet NSMutableArray *views;
}
@end
#导入
@接口子ViewOneController:UIViewController{
IBUILABEL*标签;
IBUIButton*按钮;
}
@属性(保留,非原子)IBUILabel*标签;
@属性(保留,非原子)IBUIButton*按钮;
-(iAction)On按钮单击:(id)发件人;
@结束
和subviewtowcontroller.h
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
IBOutlet NSMutableArray *views;
}
@property (nonatomic, retain) IBOutlet NSMutableArray *views;
@end
#import <UIKit/UIKit.h>
@interface SubViewOneController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIButton *button;
}
@property (retain,nonatomic) IBOutlet UILabel *label;
@property (retain,nonatomic) IBOutlet UIButton *button;
- (IBAction) OnButtonClick:(id) sender;
@end
#import <UIKit/UIKit.h>
@interface SubViewTwo : UIViewController {
IBOutlet NSMutableArray *views;
}
@end
#导入
@接口子视图二:UIViewController{
IBNSmutableArray*视图;
}
@结束
如果你能给我一个简短的解释,我会非常高兴的。
提前多谢
benny这里发生了几件事:
@接口子视图二:UIViewController{
@implementation SubViewTwoController
最简单的修复方法是将SubViewTwoController.h中的@interface行更改为:
@接口子ViewTwoController:UIViewController{
然后别忘了导入"subviewtowcontroller.h在您的
RootViewController.m文件中。非常感谢您的帮助!它都已成功编译。但现在,当点击应调用subviewtower的菜单点时,应用程序崩溃。请参阅此处的错误报告,这是因为我这样做了:看起来您忘记了.m中的@synthesis按钮;
再次感谢。我修复了它以及由此产生的错误。不幸的是,应用程序一直崩溃/冻结。调试器控制台提供以下输出:“由于未捕获异常'NSInternalInconsistencyException'终止应用程序,原因:'-[UIViewController loadView]加载了“SubViewTwo”nib,但未设置视图输出。”在这里查看我的代码:这意味着您没有在XIB文件中正确连接东西。请返回教程,其中说“突出显示文件的所有者,然后从菜单栏单击“工具”,然后单击“身份检查器”。然后在Interface Builder中重新布线。