0

我有 IBAction 和 Method。我的目的是我想将 buttonSignIn 的 IBAction 调用到方法 getData 中。在这种情况下,我希望这个应用程序自动登录而不输入用户名和密码,但它没有用。下面是我的代码:

-(void)storeData
{
    NSString *usr = [_txtUsername stringValue];
    NSString *pwd = [_txtPwd stringValue];
    
    NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
    [store setObject:usr forKey:@"usrname"];
    [store setObject:pwd forKey:@"usrpwd"];
    
    [store synchronize];
}

-(void)getData
{  
    if ([_remCheckbox state] == NSOnState)
    {
        NSUserDefaults *store = [NSUserDefaults standardUserDefaults];
        
        NSString *un = [store objectForKey:@"usrname"];
        NSString *pw = [store objectForKey:@"usrpwd"];
        
        _txtUsername.stringValue = un;
        _txtPwd.stringValue = pw;
        
        //call event IBAction
        [self buttonSignIn:self];
        
    }  
}

- (IBAction)buttonSignIn:(id)sender
{
    [self storeData];
    
    //Code for login suppose to work here
    .........
    ......... 
}

我使用 [self buttonSignIn:self]; 但它没有用。请帮忙。

4

1 回答 1

1

利用:

[self buttonSignIn:nil]; 

您也可以使用performSelectorOnMainThread:.

如果你想用来self执行你的调用,那么nil作为参数而不是self.

IE

[self buttonSignIn:nil];
于 2012-09-13T09:06:55.280 回答