아이폰 SDK에 상당히 익숙합니다.이 답변이 터무니없이 분명하다면 용서해주십시오.문제 설정 UILabel (iPhone SDK)의 가치
은 내가 .xib 파일에 연결된의 ViewController
가 나는 또한 MyCustomClass라는 사용자 정의 클래스를이 (가 FirstViewController라고합니다)가 있습니다.
:- (void)setTheText {
[myLabel setText:@"foo"];
}
내가
지금까지, 나는이 작업을 수행 한 FirstViewController.xib에 레이블의 텍스트를 설정하려면이 메소드를 호출 할 :이 클래스에서는,이 같은 방법을
"Object"를 Interface Builder로 드래그하여 클래스를 MyCustomClass로 설정하십시오. MyCustomClass의 IBOutlet 'myLabel'을 뷰의 UILabel에 연결했습니다. 그러나
, 내가 프로그램을 실행하고, 같은 것을 (FirstViewController.m에) 레이블을 설정하는 버튼을 누를 때 :
- (IBAction)doSomething:(id)sender {
MyCustomClass *customClass = [MyCustomClass alloc] init];
[customClass setTheText];
}
이 비록 설정하지 않습니다. NSLog(@"%@",[myLabel text]);
returns (null)
Xcode는 오류나 경고를 표시하지 않습니다. 무엇이 잘못 될 수 있습니까?
감사합니다,
마이클
추가 정보 : MyCustomClass.h에
인터페이스 : 여기에서는 CustomClass의
이#import <UIKit/UIKit.h>
@interface MyCustomClass : NSObject {
UILabel *myLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
- (void)setTheText;
@end
MyCustomClass에 대한 인터페이스를 게시 할 수 있습니까? myLabel을 어떻게 정의합니까? – Dana
메인 포스트에 추가했습니다. – Michael