我对iOS很新,我有一个问题。
我有一个带登录表单和按钮的视图。
我想这样做,一旦按下按钮,就会处理登录,如果成功,它会加载标签栏控制器的第一个标签。
我该怎么做?我尝试过创建一个手动segue并加载它,但这不起作用:(
这是我登录后发生的事情的代码(它是一个GitHub登录表单):
- (IBAction)login:(id)sender {
Boolean error = NO;
NSString* username = _usernameField.text;
NSString* password = _passwordField.text;
UIColor *red = [UIColor colorWithRed:255/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
UIColor *black = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1.0f];
GitHub* github = [[GitHub alloc] init];
bool result = NO;
// Checking for blanks
if([username isEqualToString:@""])
{
[_usernameLabel setTextColor:red];
error = YES;
}
else
{
[_usernameLabel setTextColor:black];
}
if([password isEqualToString:@""])
{
[_passwordLabel setTextColor:red];
error = YES;
}
else
{
[_passwordLabel setTextColor:black];
}
if(!error)
{
result = [github loginWithUsername:username AndPassword:password];
if(result == YES)
{
// Logged in successfully!
[_errorLabel setHidden:YES];
NSLog(@"YEP");
[self performSegueWithIdentifier:@"loginSegue" sender:self];
}
else
{
// Error Handling
[_errorLabel setText:@"Error: Incorrect Username / Password"];
[_errorLabel setHidden:NO];
[_passwordField setText:@""];
}
}
else
{
// Error Handling
[_errorLabel setText:@"Error: Please correct errors below:"];
[_errorLabel setHidden:NO];
[_passwordField setText:@""];
}
}