1

我能够在我的项目中实现下面提到的库。使用的库:: https://github.com/rolandleth/LTHPasscodeViewController

输入密码并验证它是否正确后,我无法在输入密码后直接切换到选项卡栏活动,但如果我在两者之间使用 NSNotification,我可以转移控制权。

我的代码:

 - (void) receiveTestNotification:(NSNotification *) notification
{
    if ([[notification name] isEqualToString:@"TestNotification"])
        NSLog (@"Successfully received the test notification!");   
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    mainTabViewController *objSec=[storyboard instantiateViewControllerWithIdentifier:@"passID"];
    [self.navigationController pushViewController:objSec animated:YES];

放置 NSLog 后,我也得到了日志输出,但选项卡视图没有出现。

有没有办法在输入密码后直接调用选项卡视图。

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(receiveTestNotification:)
                                                 name:@"TestNotification"
                                               object:nil];

Tabview 使用 StoryBoard 完成。

4

1 回答 1

1

我认为这是因为该库中的回调方法是在后台线程中执行的,尝试通过在主线程上调度来包装您的代码,它应该会有所帮助:

dispatch_async(dispatch_get_main_queue(), ^{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    mainTabViewController *objSec=[storyboard instantiateViewControllerWithIdentifier:@"passID"];
    [self.navigationController pushViewController:objSec animated:YES];
}];
于 2014-01-31T14:07:30.957 回答