用其他方法调用IBAction自动执行

时间:2012-09-13 09:01:02

标签: ios

我有IBAction和方法。我的目的我想把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];但它没有用。请帮忙。

1 个答案:

答案 0 :(得分:1)

使用:

[self buttonSignIn:nil]; 

您也可以使用performSelectorOnMainThread:

如果您想使用self来执行通话,请将nil作为参数而不是self

[self buttonSignIn:nil];