ios - 根据条件导航到不同 View Controller 的按钮

标签 ios iphone objective-c segue xcode-storyboard

我是IOS的新手。我正在 IOS 中使用一个登录按钮制作登录 View Controller 。我有两个可能的 view-controllers当用户单击登录按钮时可能会显示。我正在使用 Storyboard但我只能将一个 segue 分配给一个按钮。我不知道如何执行该条件,因为我似乎无法 100% 控制 segue。
这是我的代码:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *stringreponse=[[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
   // NSLog(@"Split response %@", [splitresponse objectAtIndex:0]);
    if([stringreponse isEqualToString:@"0"])
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Wrong username or password" message:@"Wrong username or password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else
    {
        NSArray *splitresponse=[stringreponse componentsSeparatedByString:@"#"];
        if([[splitresponse objectAtIndex:0] isEqualToString:@"Parent"])
        {
            if([[splitresponse objectAtIndex:2] isEqualToString:@"yes"])
            {
                //seguechoice=@"showParentRegistration";
               //[self performSegueWithIdentifier:@"showParentRegistration" sender:self ];
            }else{
                //seguechoice=@"showSohoDashboard";
            }
        }
    }
}

最佳答案

您可以将一个 segue 分配给一个 UI 控件,但您可以将多个 segue 分配给一个 viewController。只需将它们全部添加到 viewController,给每个不同的 id,然后调用这些 id

if([[splitresponse objectAtIndex:2] isEqualToString:@"yes"])
{
    [self performSegueWithIdentifier:@"showParentRegistration" sender:self ];
}
else
{
    [self performSegueWithIdentifier:@"showSohoDashboard" sender:self ];
}

关于ios - 根据条件导航到不同 View Controller 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21157863/

相关文章:

iPhone/iOS : Best practices to shorten launch time of an app?

ios - 只能由静态库中的类访问的方法

ios - Storyboard本地化在运行时 swift

ios - 敏感信息应该存储在哪里?

c++ - 在 Xcode 调试器中自动显示 C++ 对象的属性

c++ - OpenGL 三角形 strip 上不需要的颜色褪色问题。想要在三角形上获得统一的颜色

iphone - UIButtonTypeRoundedRect 作为 accessoryView

iphone - Objective-C:在 iOS 中转发消息

objective-c - 使用 NSNumberFormatter 在 NSTextField 中自定义错误消息

objective-c - 在ios中打开视频到时间偏移