请求非结构或联合中的成员
我正在尝试在我的 AppDelegate 中进行一些保存/加载,为此我需要我的敌人和英雄精灵。我用的是cocos2d。这是收到警告的方法。
-(void)applicationDidFinishLaunchingWithOptions:(UIApplication *)application {
NSMutableArray *loadedMoles = [DataBase loadDocs];
NSMutableArray *loadedBunnies = [DataBase loadDocs];
UINavigationController *navigationController;
viewController = (RootViewController *) [navigationController.viewControllers objectAtIndex:0];
viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error
}
即使这是 AppDelegate,我已经导入了这两个类,但仍然收到错误。
I'm trying to do some saving/loading in my AppDelegate, for which I need my enemy and hero sprites. I'm using cocos2d. Here's the method that's getting the warning.
-(void)applicationDidFinishLaunchingWithOptions:(UIApplication *)application {
NSMutableArray *loadedMoles = [DataBase loadDocs];
NSMutableArray *loadedBunnies = [DataBase loadDocs];
UINavigationController *navigationController;
viewController = (RootViewController *) [navigationController.viewControllers objectAtIndex:0];
viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error
}
Even though this is the AppDelegate, I've imported both classes, and I'm still getting the errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
评论的相关部分
Jonathan
鉴于问题不仅仅是
.
与->
的问题,那么另一个主要选项是您的 viewController 确实包含任何鼹鼠或兔子。乔
Jonathan
下载的代码 (
ScaryBugs3/Classes/rootViewController.h
),但演示具有:您的等效项是否正确定义了“mole”和“bunny”?如果是这样,我将无法进一步帮助您。
乔
答案不太相关的部分
在使用 GCC 的常规 C 或 C++ 中,错误消息通常在以下情况下出现:
structptr->member
并且应该使用structvar.member
,或者structvar.member
并且应该使用structptr->member
。我相信,此时 Objective-C 与 C 足够接近,您可能需要检查
.
与->
表示法的使用。现在您的代码清晰可见,给出错误的行是:
您可能需要使用
viewController->mole
和viewController->bunny
来代替? (我不确定这一点,但就 Objective-C 是 C 的超集而言,这将是一个必要的改变。但是,Objective-C 可能不需要区分.
和->
。)Relevant portion of comments
Jonathan
Given that the problem is not just
.
vs->
, the other main option, then, is that your viewController does contain any moles or bunnies.Joe
Jonathan
In the downloaded code (
ScaryBugs3/Classes/rootViewController.h
), the demo has:Does your equivalent have 'mole' and 'bunny' properly defined? If so, I'm at a loss to help you much further.
Joe
Not very relevant portion of answer
In regular C or C++ with GCC, the error message normally occurs when either:
structptr->member
and you should usestructvar.member
, orstructvar.member
and you should usestructptr->member
.Objective-C is close enough to C at this juncture that you probably need to review your use of
.
vs->
notation, I believe.Now that your code is legible, the lines giving the error are:
You probably need to use
viewController->mole
andviewController->bunny
instead? (I'm not sure of that, but to the extent Objective-C is a superset of C, that would be a necessary change. However, it could be that Objective-C does away with the need to distinguish between.
and->
.)在您提供的链接中使用的是 RootViewController 类,并且您正在尝试使用 UINavigationController ,它根本不具有摩尔和兔子等属性,如 @Jonathan 所说
At the link you gave is used RootViewController class and you are trying to use UINavigationController that simply does not have such properties as mole and bunny as @Jonathan said
我还出现了错误“请求非结构或联合中的成员“选项””。
我只是忘记在尝试访问此实例的类中导入“Dialog.h”。
I also had the error 'Request for member "options" in something not a structure or union' come up.
Where I simply forgot to import "Dialog.h" in the class that was trying to access this instance.