开发者

Cocoa / Objective-C: Access a (Boolean) variable in different Classes

开发者 https://www.devze.com 2022-12-17 21:35 出处:网络
Situation: Noob / Xcode 3.1 I have an AppView (NSView subclass) and an AppController (NSObject subclass)

Situation: Noob / Xcode 3.1

I have an AppView (NSView subclass) and an AppController (NSObject subclass)

in AppView.h i declare a boolean (BOOL: booleanDraw), which i set to 'NO' in AppView.m

When a button is clicked it 'launches' an action (AppController .h/.m) now i want to change booleanDraw to YES when the button is clicked.

I searched and found: do it with @property okay i tried to do that but it didnt work. (because i didnt totally get what to do probably) i did:

@property BOOL booleanDraw;

(in AppView.h)

@implementation AppView

@synthesize(readwrite, nonatomic) booleanDraw;
开发者_如何学C

(in AppView.m)

AppView *obj;
obj.booleanDraw = YES;  // implicitly calls [obj setVar:3]

(in AppController.m)

Thanks for any help, i read some tutorials already but often they suggest some steps that should be basic but that dont belong to my repertoire, and the ADN often confuse me xD sorry but believe me im trying^^


You just reversed the synthesize and property statements:

in .h:

@property (nonatomic) booleanDraw;

(by default properties are readwrite, you only need to state when they are readonly)

in .m:

@synthesize booleanDraw;

In the controller you need to get the app view reference, the code you posted would not work unless you set "obj" to something.

0

精彩评论

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