开发者

using appDelegate to share data - getting "request for member in __ not in structure or union"

I've got a simple example where i have a delegate that has a string, along with a property to expose it.

myAppDelegate.h

#import <UIKit/UIKit.h>
@interface myAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UITabBarController *rootController;
    NSString* myText;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@property (nonatomic, retain) NSString *myText;
@end

myAppDelegate.m

#import "myAppDelegate.h"
@implementation myAppDelegate
@synthesize window;
开发者_StackOverflow@synthesize rootController;
@synthesize myText;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    [window addSubview:rootController.view];
    [window makeKeyAndVisible];
}

- (void)dealloc {
    [rootController release];
    [window release];
    [super dealloc];
}
@end

So in my main view controller, I try something like this:

myAppDelegate* ad = (myAppDelegate*)[UIApplication sharedApplication].delegate;
ad.myText = @"blah";

and I get: Request for member 'myText' in something not a structure or union

does anyone know why this is happening?


Have you tried using setter instead of dot notation?

[ad setMyText:@"blah"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜