开发者

Shared object with others classes?

开发者 https://www.devze.com 2023-02-24 00:32 出处:网络
I just started learning objective c. I have this little problems and questions, hope you guys could help me.

I just started learning objective c. I have this little problems and questions, hope you guys could help me.

I have a ViewController, I called it: GameViewController.

This GameViewController, will call a model class, "PlayerModel"(NSObject) and this PlayerModel contains "PlayerProfile" object (its a NSObject).

The viewDidLoad in GameViewController will call and initiate model class:

playerModel = [[PlayerModel alloc] initWithInt:playerID];

Then, in my PlayerModel initWithInt method, I populate PlayerProfile data by fetching the data from online database. I manage to populate the data, but when I want to call it in ga开发者_如何学GomeViewController

// This is gameViewController.m
....
playerModel.playerProfile.name;

But i got this error message: "Property name not found on object of type PlayerProfile"

I NSLog the playerProfile in gameViewController, its "(null)", whereas when I NSLog in the playerModel, it has some values. How do I pass this values and make it universal, so that others classes can make use (set the value) of it?


Regarding the "Property name not found," I assume that's a compile error. You probably have failed to #import PlayerProfile.h in GameViewController.

If gameViewController is nil in GameViewController then either you have not actually initialized it, or playerModel is nil. Are you sure that you're checking it after viewDidLoad actually runs? This can be later than you think.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号