2010-06-26 2 views
2

간단한 예제가 있습니다. 여기에 문자열이있는 델리게이트와 노출 특성이 있습니다.appDelegate를 사용하여 데이터 공유 - "구조체 또는 공용체가 아닌 __에있는 멤버 요청"가져 오기

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'

왜 이런 일이 일어나는 지 아십니까?

답변

1

도트 표기법 대신 setter를 사용해 보셨습니까?

[ad setMyText:@"blah"]; 
관련 문제