请求非结构或联合中的成员

发布于 2024-10-12 04:39:07 字数 569 浏览 7 评论 0原文

我正在尝试在我的 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 技术交流群。

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

发布评论

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

评论(3

花开半夏魅人心 2024-10-19 04:39:07

评论的相关部分

Jonathan

鉴于问题不仅仅是 .-> 的问题,那么另一个主要选项是您的 viewController 确实包含任何鼹鼠或兔子。

我正在使用 http://www.raywenderlich.com/1914/how-to-save-your-app-data-with-nscoding-and-nsfilemanager。 (那里有代码可供下载。)

正在做:

viewController->mole=loadedMoles;

'struct RootViewController' 没有名为 'mole' 的成员

如何将其添加到 viewController 中?

虽然在教程中他们使用

NSMutableArray *loadedBugs = [ScaryBugDatabase loadScaryBugDocs];
RootViewController *rootController = (RootViewController *)
                       [navigationController.viewControllers objectAtIndex:0];
rootController.bugs=loadedBugs; 

Jonathan

下载的代码 (ScaryBugs3/Classes/rootViewController.h),但演示具有:

@class EditBugViewController;
@interface RootViewController : UITableViewController {
    NSMutableArray *_bugs;
    EditBugViewController *_editBugViewController;
}

@property (retain) NSMutableArray *bugs;
@property (retain) EditBugViewController *editBugViewController;

@end

您的等效项是否正确定义了“mole”和“bunny”?如果是这样,我将无法进一步帮助您。

我从未下载过源代码,所以我没有看到任何内容。谢谢,我想知道他是否可能有错误作为数组而不是错误精灵。

答案不太相关的部分

在使用 GCC 的常规 C 或 C++ 中,错误消息通常在以下情况下出现:

  • 您使用 structptr->member 并且应该使用 structvar.member ,或者
  • 您使用 structvar.member 并且应该使用 structptr->member

我相信,此时 Objective-C 与 C 足够接近,您可能需要检查 .-> 表示法的使用。

现在您的代码清晰可见,给出错误的行是:

viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error

您可能需要使用 viewController->moleviewController->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

I'm using the tutorial at http://www.raywenderlich.com/1914/how-to-save-your-app-data-with-nscoding-and-nsfilemanager. (There is code there to download.)

Doing:

viewController->mole = loadedMoles;

says

'struct RootViewController' has no member named 'mole'

How do I add it to viewController?

Although in the tutorial they use

NSMutableArray *loadedBugs = [ScaryBugDatabase loadScaryBugDocs];
RootViewController *rootController = (RootViewController *)
                       [navigationController.viewControllers objectAtIndex:0];
rootController.bugs = loadedBugs; 

Jonathan

In the downloaded code (ScaryBugs3/Classes/rootViewController.h), the demo has:

@class EditBugViewController;
@interface RootViewController : UITableViewController {
    NSMutableArray *_bugs;
    EditBugViewController *_editBugViewController;
}

@property (retain) NSMutableArray *bugs;
@property (retain) EditBugViewController *editBugViewController;

@end

Does your equivalent have 'mole' and 'bunny' properly defined? If so, I'm at a loss to help you much further.

Joe

I never downloaded the source code, so I didn't see any of that. Thanks, I was wondering if he might have bugs as an array instead of a bug sprite.

Not very relevant portion of answer

In regular C or C++ with GCC, the error message normally occurs when either:

  • You use structptr->member and you should use structvar.member, or
  • You use structvar.member and you should use structptr->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:

viewController.mole = loadedMoles; //error
viewController.bunny = loadedBunnies; //error

You probably need to use viewController->mole and viewController->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 ->.)

栖迟 2024-10-19 04:39:07

在您提供的链接中使用的是 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

何处潇湘 2024-10-19 04:39:07

我还出现了错误“请求非结构或联合中的成员“选项””。

@interface Dialog :  NSManagedObject {}
@property (nonatomic, retain) NSSet* options;

@implementation Dialog
@dynamic options;

我只是忘记在尝试访问此实例的类中导入“Dialog.h”。

I also had the error 'Request for member "options" in something not a structure or union' come up.

@interface Dialog :  NSManagedObject {}
@property (nonatomic, retain) NSSet* options;

@implementation Dialog
@dynamic options;

Where I simply forgot to import "Dialog.h" in the class that was trying to access this instance.

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