我有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];但它没有用。请帮忙。
答案 0 :(得分:1)
使用:
[self buttonSignIn:nil];
您也可以使用performSelectorOnMainThread:
。
如果您想使用self
来执行通话,请将nil
作为参数而不是self
。
即
[self buttonSignIn:nil];