【问题标题】:A button which navigates to different view controllers depending on the condition根据条件导航到不同视图控制器的按钮
【发布时间】:2014-01-16 09:26:32
【问题描述】:

我是 IOS 新手。我正在IOS中使用一个登录按钮制作登录视图控制器。当用户单击登录按钮时,可能会显示两个可能的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";
            }
        }
    }
}

【问题讨论】:

  • 请打印stringreponse结果。
  • 通过 viewController 将 segue 分配给其他两个 viewController,并为这两个控制器中的每一个赋予两个不同的标识符,然后执行您想要的操作。
  • Thanx 想通了

标签: ios iphone objective-c segue xcode-storyboard


【解决方案1】:

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

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

【讨论】:

  • 谢谢西蒙,我也想通了。
【解决方案2】:

在情节提要中创建从源视图控制器到目标视图控制器(不是按钮)的 2 个连接。插入两个不同的标识符,当按下按钮时执行条件并运行 segue 取决于条件:

if(CONDITION TO RUN SEGUE !)
{
   [self performSegueWithIdentifier:@"SEGUEIDENTIFIER1" sender:self ];
}else {
    [self performSegueWithIdentifier:@"SEGUEIDENTIFIER2" sender:self ];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多