我是一名從遠處國家學習英語和Objective-C的學生。當我嘗試在文本框中輸入時,出現EXC_BAD_ACCESS(代碼= 2地址= 0x0)錯誤
下面的代碼是測試代碼,當我在文本字段中鍵入內容時。然後立即在命令行上打印一個字符。
但是當我觸摸正在運行的應用程序的文本。發生模糊的錯誤。
#import "SimpleViewController.h"
#import "SimpleTextFieldDelegate.h"
@interface SimpleViewController()
@end
@implementation SimpleViewController
@synthesize field;
@synthesize label;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
// Nothing special in here.
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Do this will be printed on command line?");
[self.field setDelegate: [[SimpleTextFieldDelegate alloc] init]];
}
@end
這是SimpleViewController類實現代碼。
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
<- error caused at here.
}
}
爲什麼我得到這個錯誤?我無法猜出任何猜測。
嘗試保留simpletextfielddelegate作爲視圖@property在@ JB13屬性代碼中的接口代碼完全存在於「SimpleViewController.h」接口 – JB13
,但結果是相同的。 – Notice
它看起來像。沒有什麼特別的可能導致錯誤。我剛剛初始化委託..,請幫助我.. – Notice