1

您好我有一個modalview控制器彈出在主菜單上,用戶成功登錄後。這用於其他角色,需要保存在userdefaults 。模式被正確解除,但它沒有經過-viewdidappear方法。我編寫了程序,以便在選擇角色後,它會根據角色加載包含填充數據的整個主菜單。我曾經做過「presentViewController:roleVC」而不是模式,但決定不再使用它,因爲我無法修改VC的大小(我希望它以模態樣式顯示)。無論如何,使用presentViewController,父VC會經歷-viewdidappear,這對我來說是完美的。現在我不知道如何強制它解散模態後再次通過viewdidappear。ipad modalviewcontroller當解僱不去看viewdidar的主視圖控制器

下面是一些屏幕,使其更容易理解。

enter image description here

這就是我的那個主菜單的viewdidappear內。 (....轉發流量VC)

if([[NSUserDefaults standardUserDefaults] objectForKey:@"role"] == nil){ 
     /*UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"]; 
     [self presentViewController:roleVC animated:YES completion:^{}];*/ 
     UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"]; 
     roleVC.modalPresentationStyle = UIModalPresentationFormSheet; 
     roleVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     [self presentViewController:roleVC animated:YES completion:nil]; 
     roleVC.view.superview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
     roleVC.view.superview.bounds = CGRectMake(0, 0, 500, 600); 
    }else{ 
     if([[NSUserDefaults standardUserDefaults] integerForKey:@"role"] == 1){ 
      MainAdminDashboardViewController *adminVC = (MainAdminDashboardViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"MainAdminDashboardViewControllerID"]; 
      [self presentViewController:adminVC animated:NO completion:nil]; 
     }else{ 
      [self performSegueWithIdentifier:@"SeguePushToMatsFromSwitchBoard" sender:self]; 
     } 
    } 

正如你所看到的,一個角色分配後SEGUE得到推動。

這是一個按鈕被點擊

- (IBAction)btnRole1:(id)sender { 
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
    [prefs setInteger:2 forKey:@"role"]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

時,當該按鈕被點擊(使用presentviewcontroller)之前,它會經過viewdidappear的解僱。現在它不。有關如何處理此問題的任何建議?我很新,所以它都是混亂的,所以任何關於處理這個問題的最佳實踐的建議都是可以理解的。

謝謝!

編輯: 另外,要清楚,當我在做一個presentViewController沒有編輯的modalproperties;它將關閉該VC,然後將經過viewdidappear(如roleVC.modalPresentationStyle = UIModalPresentationFormSheet。) 。 這就是我之前調用它的方式,在我解僱它之後它會出現viewdidappear。

UIViewController *roleVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDRoleViewController"]; 
      [self presentViewController:roleVC animated:YES completion:^{}]; 

UPDATE: 所以我試圖把一個協議(委託)上彈出。我的問題是這個壽命,它完美的工作,如果它試圖調用一個segue,以便它可以替換細節視圖。但是,我希望在Splitviewcontroller上有完全不同的東西,所以我會調用一個presentViewcontroller。它不會出現。

這是我的代碼。

這是模式的VC上的VC

-(IBAction)role1:(id)sender{ 
    if(roleViewDelegate != nil){ 
     [roleViewDelegate dismissVC]; 
    } 
} 

在VC執行調用它們

-(void)dismissVC{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    UISToryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    // pop up another VC that contains tabbed menus to replace Split View 
    AdminMenuViewController *adminVC = [storyboard instantiateViewControllerWithIdentifier:@"SBIDAdminVC"]; 

    [self presentViewController:adminVC animated:YES completion:nil] 
} 

回答

0

對於那些(角色控制)

@protocol RoleViewDelegate<NSObject> 
-(void)dismissVC; 
@end 
@interface RoleViewVC : UIViewController 
@property(nonatomic, strong) id roleViewDelegate; 

誰可能在彈出視圖控制器時有相同的問題,並且在解散後需要做其他事情,我解決了它NG這個

https://stackoverflow.com/a/7194182/639713

基本上,將延遲,因爲由於某種原因,它採取了一些針對modalviewcontroller被刪除。我添加了一個委託,它將調用發生延遲的另一種方法。

相關問題