我剛剛開始學習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