我有一个简单的例子,我有一个带有字符串的委托,以及一个公开它的属性。
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;
@synthesize rootController;
@synthesize myText;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:rootController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[rootController release];
[window release];
[super dealloc];
}
@end
所以在我的主视图控制器中,我尝试这样的事情:
myAppDelegate* ad = (myAppDelegate*)[UIApplication sharedApplication].delegate;
ad.myText = @"blah";
我得到:在非结构或联合的情况下请求成员'myText'
有谁知道为什么会这样?
答案 0 :(得分:1)
您是否尝试使用setter而不是点符号?
[ad setMyText:@"blah"];