我有一个UIViewController
with 按钮,它带来了另一个UIViewController
. 单击按钮,如图所示,NSLog
完成后,我想发送通知以加载另一个viewcontroller
. 好吧,虽然看起来一切都做对了,但不知何故它不起作用并且UIViewController
没有出现。这是代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(infoPage:)
name:@"InfoPage" object:nil ];
-(void) infoPage:(NSNotification*)notification
{
NSLog(@"Code executing in Thread %@",[NSThread currentThread] );
InfoCtrol *i = [[InfoCtrol alloc] init];
i.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:i animated:YES];
}
我的 tabbaritem 按钮
-(void)info {
[[NSNotificationCenter defaultCenter] postNotificationName:@"InfoPage"
object:nil
userInfo:nil];
NSLog(@"test not");
}
我认为我的问题是:它不在 mainThread 但我不知道应该如何解决:
我也使用了这个,但它没有带来 UIViewController:
[self performSelectorOnMainThread:@selector(test) withObject:nil waitUntilDone:NO];
-(void)test{
[[NSNotificationCenter defaultCenter] postNotificationName:@"InfoPage"
object:nil
userInfo:nil];
}
如果我只是将此代码放在按钮中,它会显示UIViewController
,但我想使用NSNotificationCenter
InfoCtrol *i = [[InfoCtrol alloc] init];
i.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:i animated:YES];
我的日志:
Code executing in Thread <NSThread: 0x1fd7c7e0>{name = (null), num = 1}
更新:
How should i remove last thread from mainThread