2013-10-25 45 views
-2

我使用的是委託UITabbarController像這樣的過渡動畫:ViewDidAppear不會被調用

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 

    NSArray *tabViewControllers = tabBarController.viewControllers; 
    UIView * fromView = tabBarController.selectedViewController.view; 
    UIView * toView = viewController.view; 
    if (fromView == toView) 
     return TRUE; 
    NSUInteger fromIndex = [tabViewControllers indexOfObject:tabBarController.selectedViewController]; 
    NSUInteger toIndex = [tabViewControllers indexOfObject:viewController]; 

    [UIView transitionFromView:fromView 
        toView:toView 
        duration:0.3 
        options: toIndex > fromIndex ? UIViewAnimationOptionTransitionFlipFromLeft : UIViewAnimationOptionTransitionFlipFromRight 
       completion:^(BOOL finished) { 
        if (finished) { 
         tabBarController.selectedIndex = toIndex; 
        } 
    }]; 
    return true; 
} 

只有這打破了我的整個ViewDidAppear上的意見。我重置UIWebView到主頁選項卡之間切換時,但這不工作了。有什麼建議麼?這裏是我的VieDidLoad

-(void)viewDidAppear:(BOOL)animated{ 

    [super viewDidAppear:animated]; 
    _progressProxy = [[NJKWebViewProgress alloc] init]; 
    _webView.delegate = _progressProxy; 
    _progressProxy.webViewProxyDelegate = self; 
    _progressProxy.progressDelegate = self; 

    [self loadSite]; 
    [TestFlight passCheckpoint:@"Bekijkt homepage"]; 
} 

[self loadSite];被定義爲:在提前

-(void)loadSite 
{ 
    NSString *dealerurl = [[NSUserDefaults standardUserDefaults] stringForKey:@"name_preference"]; 
    NSString *urlAddress= @"http://www.sportdirect.com/shop/"; 
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlAddress]]; 
    [_webView loadRequest:req]; 
    [[_webView scrollView] setBounces: NO]; 
} 

感謝。

+1

你的代碼看起來OK,設置viewDidAppear一個Breakoint並嘗試與viewWillAppear中 –

+2

@DavidG更換您的viewDidAppear梅索德。原來它居然達到斷點'自loadsite'設置每一個開關。它只是不改變'UIWeview' .. –

+0

OK,在第一行設置一個斷點 - (空)loadSite,檢查值,檢查是否有些東西是零。我想補充一點梅索德認識到,如果沒有web視圖加載失敗: - (無效)webView的:(UIWebView的*)webView的didFailLoadWithError:(NSError *)錯誤{ 的NSLog(@ 「錯誤」); } –

回答

1

變化:

[_webView loadRequest:req]; 

這樣:

self.webView loadRequest:req; 

我認爲這將撤消nil