我刚刚开始学习Objective C/Cocoa,我知道内存管理是多么重要,我相信这个错误是我一直在关注的。编程接收信号:EXC_BAD_ACCESS。该怎么做?
我有一个非常非常简单的屏幕:两个UITextView,一个按钮,一个UILabel。
我的头文件有:
@interface PontaiViewController : UIViewController {
UITextField *loginField;
UITextField *passwordField;
UILabel *userID;
}
@property (nonatomic, retain) IBOutlet UITextField *loginField;
@property (nonatomic, retain) IBOutlet UITextField *passwordField;
@property (nonatomic, retain) IBOutlet UILabel *userID;
- (IBAction) btnLoginClicked:(id) sender;
实施有:
@implementation PontaiViewController
@synthesize loginField;
@synthesize passwordField;
@synthesize userID;
-(IBAction) btnLoginClicked:(id)sender {
NSString *string1 = @"username=";
NSString *string2 = [string1 stringByAppendingString:(loginField.text)];
NSString *string3 = [string2 stringByAppendingString:(@"&password=")];
NSString *post = [string3 stringByAppendingString:(passwordField.text)];
NSLog(@"The post is %@", post);
userID.text=loginField.text;
[string1 release];
[string2 release];
[string3 release];
[post release];
}
,并与
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.loginField=nil;
self.passwordField=nil;
self.userID=nil;
}
- (void) dealloc {
[super dealloc];
[loginField release];
[passwordField release];
[userID release];
}
完成当我运行这个演示,并尝试写som在TextView中,我得到这个错误。
它可能是什么?
的问候,费利佩
错误发生在哪里?在'userID.text = loginField.text;'?如果是这样,你确定你将'userID'字段连接到了Interface Builder中的某些东西吗? – 2012-03-01 22:17:58