이 사이트를 처음 사용하기 때문에 Objective-c를 처음 사용하게되었습니다. 이것은 간단한 질문이지만 어떤 이유로 나는 많은 문제가 있다고 확신합니다. 이 응용 프로그램은 사용자가 텍스트 필드를 통해 문자열을 입력하도록 설계되었습니다. 그러면 나머지 문장을 선택하여 표시합니다. 문제는 my * 이름이 키보드 메소드 후에 유지되고 changelabel 메소드에서 한 번 작동한다는 것입니다. 그럼 내가 다시 changelabel 메서드를 호출하는 버튼을 누르면, 이름이 공개되고 응용 프로그램을 충돌하는 것 같습니다. # import를 # import를 "Array.h"NSString이 한 번 작동하지 않는다면
@interface RandomBoredViewController : UIViewController {
UILabel *label;
UIButton *button;
UITextField *textField;
Array *array;
NSString *name;
NSString *description;
NSMutableString *whole;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) Array *array;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSMutableString *whole;
-(IBAction) keyBoard;
-(IBAction) changeLabel;
@end
내하는 .m
#import "RandomBoredViewController.h"
@implementation RandomBoredViewController
@synthesize label;
@synthesize checker;
@synthesize button;
@synthesize textField;
@synthesize array;
@synthesize name;
@synthesize description;
@synthesize whole;
-(IBAction) changeLabel {
NSLog(@"Button being pushed");
description = [array getString];
NSLog(@"%@",description);
NSLog(@"%@",name);
name = [NSString stringWithString:name];
whole = [NSMutableString stringWithString:name];
NSLog(@"%@",name);
NSLog(@"%@",whole);
[whole appendString:description];
NSLog(@"%@",name);
NSLog(@"%@",whole);
label.text = whole;
NSLog(@"%@",name);
}
-(IBAction) keyBoard {
name = [NSString stringWithString:textField.text];
NSLog(@"%@",name);
label.text = [NSString stringWithString: name];
[textField resignFirstResponder];
}
- (void)viewDidLoad {
[super viewDidLoad];
array = [[Array alloc]init];
[array createArray];
NSLog(@"%i",[array arrayCount]);
whole = [[NSMutableString alloc]init];
name = [[NSString alloc]init];
}
- (void)dealloc {
[super dealloc];
[label release];
[button release];
[textField release];
[array release];
//[name release];
[description release];
}
@end
이 줄은 약간 중복 된 것처럼 보입니다 :'name = [NSString stringWithString : name];'오류의 원인 일 수 있습니다. –