버튼 클릭시 텍스트가있는 UILabel 텍스트를 변경하려고하지만 아무 것도하지 않습니다.NSMutablearray 데이터로 UILabel의 텍스트 변경
@interface Test01AppDelegate : NSObject <UIApplicationDelegate> {
UILabel *helloLabel;
UIButton *hellobutton;
NSMutableArray *madWords;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIButton *hellowButton;
@property (nonatomic, retain) IBOutlet UILabel *hellowLabel;
@property (nonatomic, retain) NSMutableArray *madWords;
- (void) madArrays;
- (IBAction)helloYall;
@end
및
#import "Test01AppDelegate.h"
@implementation Test01AppDelegate
@synthesize window = _window;
@synthesize hellowButton;
@synthesize hellowLabel;
@synthesize madWords;
- (void) madArrays {
[madWords addObject:@"Part A"];
[madWords addObject:@"Part B"];
[madWords addObject:@"Part C"];
[madWords addObject:@"Part D"];
}
- (IBAction)helloYall {
[self madArrays];
self.hellowLabel.text = [madWords objectAtIndex:0];
}
나는
@"some text here";
으로 helloLabel 텍스트를 설정하고 그것을 잘 작동합니다. 또한 "madArrays"메서드를 "helloYall"메서드로 복사하려고 시도했지만 여전히 작동하지 않았습니다. 앞에서 말했듯이 필자는 텍스트를 수동으로 설정할 수 있으며 작동하지만 배열에서 정보를 가져오고 싶습니다. 결국, 배열을 반복하여 각 버튼 누름에서 텍스트를 가져오고 싶지만 한 번에 한 단계 씩 진행하고 싶습니다. 감사.
답변 주셔서 감사합니다. 나는 메시지의 오른쪽 부분에있는 "배열"이 무엇을 의미하는지 또는 어떤 의미인지에 대해서 조금 혼란스러워한다. – anthony
'[NSMutableArray array]'는 자동으로 릴리즈 된 NSMutableArray를 생성합니다. 'array'는 클래스 메쏘드 이름입니다. – zaph