Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 会员申请';视图';在非结构或联盟中_Objective C_Ios_Viewcontroller - Fatal编程技术网

Objective c 会员申请';视图';在非结构或联盟中

Objective c 会员申请';视图';在非结构或联盟中,objective-c,ios,viewcontroller,Objective C,Ios,Viewcontroller,我得到了标题中提到的错误 这是我的界面: #import <UIKit/UIKit.h> @class ControllerLevel1; @interface RootController : UIViewController { ControllerLevel1 *controllerLevel1; } @property (retain, nonatomic) ControllerLevel1 *controllerLevel1; @end 错误出现在[self.

我得到了标题中提到的错误

这是我的界面:

#import <UIKit/UIKit.h>

@class ControllerLevel1;

@interface RootController : UIViewController {
ControllerLevel1 *controllerLevel1;
}

@property (retain, nonatomic) ControllerLevel1 *controllerLevel1;

@end  

错误出现在
[self.view insertSubview:firstLevel.view atIndex:0]中

它正在抱怨firstLevel.view


所以,很可能您没有在ControllerLevel1.h中将“view”声明为属性。向我们显示.h文件,我们可以提供更多帮助。

什么是ControllerLevel 1?你有那门课的代码吗。它是UIViewController子类吗?它是UIViewController子类。除了创建一组新的.h和.m文件时提供的“模板”之外,没有其他代码。让我们看看.h文件,至少是其中的实例变量和属性部分。仅此而已:#import@interface ControllerLevel1:UIViewController{}@endTry传递self.view代替firstLevel.view只是为了确保错误为firstLevel.view是正确的(是的,不要运行此操作,只需编译以查看是否得到警告)。如果不是的话,那么问题出在firstLevel.view上,这是正确的。我传递了self.view来代替firstLevel.view,它编译得很好。那么firstLevel.view有什么问题?非常感谢到目前为止的帮助,顺便说一句。看起来它应该对我有用。在生成输出中查找警告?也许在项目设置中提高警告级别?尝试构建和分析,看看它是否会告诉你它不喜欢什么。所以这里有一个解决办法,但不应该这样做。传递[firstLevel view],而不是firstLevel.view。不过你不应该这么做。您使用的编译器&Xcode版本是什么?可能是一个编译器错误(?)。它起作用了,所以我现在要坚持下去,这样我就可以继续了。非常感谢你的帮助!
#import "RootController.h"
#import "ControllerLevel1.h"

@implementation RootController

@synthesize controllerLevel1;

- (void)viewDidLoad {
    ControllerLevel1 *firstLevel = [[ControllerLevel1 alloc]initWithNibName:@"ControllerLevel1" bundle:nil];
    self.controllerLevel1 = firstLevel;
    [self.view insertSubview:firstLevel.view atIndex:0];
    [firstLevel release];
    [super viewDidLoad];
}