[英]Cannot get segue to work with viewDidLoad or viewDidAppear
對於我的視圖控制器的viewDidLoad方法實現,它要求用戶訪問通訊錄。 我需要這樣做,以便如果用戶點擊警報視圖窗口上的“不允許”按鈕,那么我們會將它們隔離到另一個視圖控制器。
我的問題是segue永遠不會發生,並在控制台中顯示以下輸出:
Warning: Attempt to present <MediaCaptureVC: 0x156788c0> on <AddFriendsViewController: 0x15670dd0> whose view is not in the window hierarchy!
我嘗試了幾項沒有幫助的事情:
添加一個帶有我的segue代碼的viewDidAppear
方法實現,並在我的viewDidLoad的if語句中調用[self viewDidAppear]
。
將我的segue代碼移到viewDidLoad
最底部。
但是什么都行不通。 即使視圖在技術上正在加載,我也需要一種方法來觸發segue,因為如果他們拒絕訪問其地址簿,那么絕對沒有理由讓他們停留在視圖控制器上。
這是我的viewDidLoad
方法實現的開始,我在其中請求訪問地址簿,然后我的if(accessGranted == NO)
if語句包含以下代碼: [self performSegueWithIdentifier:@"addFriendsToMediaCaptureSegue" sender:self];
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
self.currentUser = [PFUser currentUser];
self.tableView.dataSource = self;
self.tableView.delegate = self;
//Asks for access to Address Book.
ABAddressBookRef m_addressbook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookCopyArrayOfAllPeople(m_addressbook);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
// Write your code here...
// Fetch data from SQLite DB
}
});
ABAddressBookRequestAccessWithCompletion(m_addressbook, ^(bool granted, CFErrorRef error)
{
accessGranted = granted;
NSLog(@"Has access been granted?: %hhd", accessGranted);
if(accessGranted == NO) {
[self performSegueWithIdentifier:@"addFriendsToMediaCaptureSegue" sender:self];
}
NSLog(@"Has there been an error? %@", error);
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
在您的viewDidLoad:
double delayInSeconds = 0.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SecondViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self presentViewController:vc animated:YES completion:nil];
});;
您可以嘗試移動您的performSegueWithIdentifier嗎?
dispatch_async(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"addFriendsToMediaCaptureSegue" sender:self]; });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.