我对客观的C和iOS很新颖,因为我主要是一个C++/java开发人员,我无法让我的生活得到performSegueWithIdentifier
正常工作,换句话说,它不会移动到下一个Segue公司。我正在做一个简单的登录系统,如果状态代码不是401或403,那么我有条件,然后进入主应用程序。目前在我的故事板中,我有我的主视图控制器与我的textFields和一个按钮来登录。然后,我用MainViewController
(不是按钮)和标识符MoveToMainApp
和样式model
进行了比较。在我的主视图控制器的实施文件中,我有以下方法:iOS:performSegueWithIdentifier麻烦
-(void)moveToMainApp
{
[self performSegueWithIdentifier:@"MoveToMainApp" sender:nil];
}
- (IBAction)login:(id)sender {
NSString *username = _usernameTxt.text;
NSString *password = _passwordTxt.text;
_errorLabel.text = @"";
if(username.length > 0 && password.length > 0)
{
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://samplesite.org/mobile_app"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:@"http://samplesite.org/mobile_app/login.php"
parameters:@{@"username":username, @"password":password}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
NSInteger statusCode = operation.response.statusCode;
if(statusCode == 401 || statusCode == 403)
{
_errorLabel.text = @"Invalid credentials";
}
else
{
[self moveToMainApp];
}
}];
[operation start];
}
我在这里错过了什么?
发生了什么?它打破了吗? – Dan
对不起,应该明确这一点,它不会移动到下一个赛格。 – JohnnyWineShirt
为了完成故事板的继续,您必须控制从您的登录控制器拖动到您的目标控制器,并出现一个弹出窗口,名称为manual segue,只需选择模式,现在在属性检查器中选择segue为您的那么你可以用[self performSegueWithIdentifier:@“yourIdentifier”sender:self]来调用你的segue; –