3

我是 iOS 开发的新手。我正在尝试从 xib 文件连接到情节提要。我的 xib 视图控制器有一个“登录”,如果成功应该连接到情节提要。我已经在 stackoverflow 上搜索并搜索了一个解决方案,我正在使用随处可见的这段代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    YourViewController * yourView = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"identifier ID"];

我也为我的故事板创建了一个标识符。但是,无论我尝试什么,我都不会被重定向到情节提要。登录完成后,我回到我的主视图控制器 (xib)。我应该被重定向到情节提要。这是我的代码在名为 ProfileTabView.m 的文件中的样子:

-(void) loginViewDidFinish:(NSNotification*)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    ProfileTabView * yourView = (ProfileTabView *)[storyboard instantiateViewControllerWithIdentifier:@"myID"];

}

我已经在登录成功后调用的函数中实现了这段代码。但是,故事板“故事板”从未被调用。我这样做对吗?我应该在其他任何地方编写此代码吗?

非常感谢您的帮助:)

4

2 回答 2

3

更进一步:展示新的视图控制器......

-(void) loginViewDidFinish:(NSNotification*)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    ProfileTabView * yourView = (ProfileTabView *)[storyboard instantiateViewControllerWithIdentifier:@"myID"];

    // it might be better to rename 'ProfileTabView' as 'ProfileTabViewController'
    // and 'yourView' as 'profileTabVC', by convention.  Anyway ...

    [self.presentViewController:yourView animated:YES completion:^{}];
}

如果您的登录 VC 在导航控制器中,那么您将推送新的 vc:

[self.navigationController pushViewController:yourView animated:YES]; 
于 2013-10-31T05:03:11.440 回答
1
-(void) loginViewDidFinish:(NSNotification*)notification
{
NSNotificationCenter.defaultCenter().removeObserver(self)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewControllerID") as UIViewController
    self.presentViewController(vc, animated: true, completion: nil)
}
于 2017-02-02T08:26:59.923 回答