【问题标题】:Not able to call UITabview from NSNotificationCenter in IOS无法从 IOS 的 NSNotificationCenter 调用 UITabview
【发布时间】:2014-01-31 13:32:54
【问题描述】:

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

输入 pin 码并验证它是否正确后,我无法在输入 pin 码后直接切换到选项卡栏活动,但如果我在两者之间使用 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 后,我也得到了日志输出,但选项卡视图没有出现。

有没有办法在pin-entry之后直接调用tab-view。

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

使用 StoryBoard 完成的 Tabview。

【问题讨论】:

  • 试过在 mainThread 上切换 UI 吗?

标签: ios objective-c ios7 nsnotificationcenter uitabview


【解决方案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];
}];

【讨论】:

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