0
嘗試在線程中使用類變量並獲取EXC_BAS_ACCESS。 代碼片段:線程參數Objective-C
@interface ViewController : UIViewController {
NSString* accountLoginName;
NSString* accountPassword;
}
實施:
accountLoginName = [NSString stringWithString:textFieldLoginName.text];
accountPassword = [NSString stringWithString:textFieldPassword.text];
[self performSelectorInBackground:@selector(loginAtBackgroundSelector:) withObject:nil];
-(void)loginAtBackgroundSelector:(UIAlertView*)alert
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@\n%@", accountLoginName, accountPassword);
[self login];
[self dismissAlert:alert];
[pool release];
}
只是想寫信給控制檯,在這部分代碼得到錯誤,但在loginAtBackgroundSelector錯誤的時間出現的時間。在實施
@interface ViewController : UIViewController {
NSString* accountLoginName;
NSString* accountPassword;
}
@property(nonatomic, retain) NSString* accountLoginName;
@property(nonatomic, retain) NSString* accountPassword;
這(在地方,你分配值):Additionaly中的dealloc
self.accountLoginName = [NSString stringWithString:textFieldLoginName.text];
self.accountPassword = [NSString stringWithString:textFieldPassword.text];
[self performSelectorInBackground:@selector(loginAtBackgroundSelector:) withObject:nil];
:
-(AlertType)login
{
NSLog(@"%@\n%@", accountLoginName, accountPassword);
}
這就是訣竅:)上帝,我很愚蠢:D – user1098429 2011-12-14 18:49:54