2011-12-14 10 views
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の誤差が随時表示されます。

-(AlertType)login 
{ 
    NSLog(@"%@\n%@", accountLoginName, accountPassword); 
} 

答えて

0

インターフェイスでこれを試してみてください:

(あなたが値を割り当てる代わりに)実装で
@interface ViewController : UIViewController {  
    NSString* accountLoginName; 
    NSString* accountPassword; 
} 
@property(nonatomic, retain) NSString* accountLoginName; 
@property(nonatomic, retain) NSString* accountPassword; 

そして、この:のdeallocで

self.accountLoginName = [NSString stringWithString:textFieldLoginName.text]; 
self.accountPassword = [NSString stringWithString:textFieldPassword.text]; 
[self performSelectorInBackground:@selector(loginAtBackgroundSelector:) withObject:nil]; 

がAdditionaly:

-(void)dealloc { 
    [accountLoginName release]; 
    [accountPassword release]; 
    [super dealloc]; 
} 

lps。

+0

それはトリックでした:)神、私は愚かです:D – user1098429

関連する問題