2014-01-31 59 views
1

我能夠在我的項目中實現下面提到的庫。 使用過的庫:: https://github.com/rolandleth/LTHPasscodeViewController無法從IOS中的NSNotificationCenter調用UITabview

輸入pin碼後,在驗證它是正確的之後,我無法直接在pin碼輸入之後切換到tab-bar活動,但如果我在兩者之間使用了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的也是我收到的日誌輸出,但標籤視圖不來了。

有沒有辦法在引腳輸入後直接調用tab視圖。

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

Tabview使用StoryBoard完成。

+1

想這樣做對mainThread該UI切換? – chandu

回答

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]; 
}]; 
相關問題