我正在尝试从服务器成功发送基本登录应用程序的消息后转到页面。目前,当我获得成功的日志时,它会移动到黑屏,就像它看起来不是那里的视图控制器一样。然而,有一个视图控制器与我想要去的类一致。这是我到目前为止的代码
if([serverOutput isEqualToString:@"Yes"])
{
NSLog(@"Yes there was a match");
WelcomeScreenViewController *newview =[[WelcomeScreenViewController alloc] init];
[self presentViewController:newview animated:YES completion:nil];
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
`}
为什么在我成功登录后不能将我带到欢迎屏幕?我是否需要欢迎root控制器,然后按下登录屏幕。为什么我不能以编程方式使用if语句移动到视图控制器?
` - (IBAction)loginbuttonpressed:(id)sender {
//Trim white space off username/password
NSString *rawEmail = [_UIEmailTextField text];
NSString *rawPass = [_UIPasswordTextField text];
NSString *trimmedEmail = [rawEmail stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *trimmedPass = [rawPass stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//Check if text field is empty
if([_UIEmailTextField.text length] > 0 && [_UIPasswordTextField.text length] > 0)
{
NSString *post =[NSString stringWithFormat:@"userName=%@&userPassword=%@",trimmedEmail, trimmedPass];
NSString *hostStr = @"http://server name?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"])
{
NSLog(@"Yes there was a match");
WelcomeScreenViewController *newview =[[WelcomeScreenViewController alloc] init];
[self presentViewController:newview animated:YES completion:nil];
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];`
So all of this is run when you hit a log in button. I had it being a seque when you click log in but then if the log in fails it still logs in.
答案 0 :(得分:1)
当测试segue之前的值时,你应该从viewController而不是UIButton中获取segue。然后使用performSegueWithIdentifier执行添加到控制器的segue。然后在prepareForSegue中,您可以测试不同的segues并将事物传递给destinationViewController。
Perform Segue programmatically and pass parameters to the destination view