2014-05-22 3 views
0

NSTextView 개체의 문자열 내용을 수정하려고합니다. 지금까지 나는 다음 코드로 작동하도록 만들었습니다.IBAction 메서드 외부에서 NSTextView 내용을 변경하십시오.

.H 파일

#import "AppDelegate.h" 

@interface InterfaceManager : AppDelegate { 
    IBOutlet NSTextView *content; 
} 

-(IBAction)displayOutput:(id)sender; 

@property (assign) IBOutlet NSWindow *window; 

@end 

하는 .m 파일을 모두 완벽하게 잘 작동하고 내가 원하는 정확히 수행

#import "InterfaceManager.h" 

@implementation InterfaceManager 

-(IBAction)displayOutput:(id)sender { 
    [content setString:@"This is a string"]; 
} 

@end 

.


그러나 void 메소드에서 동일한 작업을 수행 할 수 있어야합니다. 여기 내가 시도한 것이있다.

.H 파일

#import "AppDelegate.h" 

@interface InterfaceManager : AppDelegate { 
    IBOutlet NSTextView *content; 
} 

-(void)displayOutput:(NSString *)string; 

@property (assign) IBOutlet NSWindow *window; 

@end 

하는 .m 파일

#import "InterfaceManager.h" 

@implementation InterfaceManager 

-(void)displayOutput:(NSString *)string { 
    [content setString:string]; 
} 

@end 

작동하지 않습니다.

내가 뭘 잘못하고 어떻게 해결할 수 있습니까?

미리 감사드립니다. :)

답변

0

정확하게 이해한다면 버튼을 눌렀을 때 텍스트를 설정하지만 사용자가 버튼을 누르지 않아도 텍스트를 설정하려고합니다. 그런 경우라면 "무효화 방법"이 필요하지 않습니다. 어떤 방법으로도 무효화 할 수 있습니다. 예를 들어,이 코드를 사용하여 처음 화면을 입력 할 때 옵션 화면에서 클라이언트 이름을 설정합니다.

-(void)myContentSettingMethod { 
    [self.content setString:@"This is a string"]; 
} 

를하고 내용을 설정할 때마다 다음을 호출

- (void)viewDidLoad { 

    // All games allow a client and rewards 
    if (self.currentClient) { 
     self.clientInput.text = self.currentClient; 
    } 
} 

당신이 문자열을 설정하기 위해 별도의 방법을 원한다면, 당신이 이런 식으로 뭔가를 사용할 수 있다고 생각합니다.

관련 문제