2012-09-06 42 views
0

我有UINavigationController包含UIViewController(說'FirstVC')。這個'FirstVC'包含一個UIScrollView,在這個UIScrollView的每個頁面上,我增加了另一個UIViewCotroller(說'SecondVC')。這SecondVC包含一個UIWebView有幾個鏈接。我想再推一個UIViewController(比如'ThirdVC'),其上面有一個UIScrollView。但是當我嘗試做同樣的事情時,它會崩潰我的應用程序。 這裏是代碼,我已申請:應用程序崩潰,試圖從web視圖委託推新的視圖控制器

FirstVC

- (void)viewDidLoad{ 

    [super viewDidLoad]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ShowThirdVCNotification:) name:@"ShowThirdVC" object:nil]; 

} 

-(void)showAlbumNotification:(id)notificationObject{ 
    NSLog(@"ShowThirdVCNotification: %@", [notificationObject object]);// It's an array 

    ThirdVC *controller = [[ThirdVC alloc] initWithNibName:@"ThirdVC" bundle:nil]; 
    [controller setImageArr:[notificationObject object]]; 
    [self.navigationController pushViewController:controller animated:NO]; 
} 

/* SecondVC.view被添加到FirstVC的滾動視圖時,它加載*/

SecondVC

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 
NSString *urlStr = [NSString stringWithFormat:@"%@", [request URL]]; 

    if ([[urlStr lastPathComponent] rangeOfString:@".jpg"].length) { 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"ShowAlbum" object:self.imageDetailArr]; 
     return NO; 
    } 
return YES; 
} 

在線程1 it li STS如下:

4 0x00b0a8ab in -[UIWebScrollView didMoveToWindow]() 
5 0x007a583e in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
6 0x007af6d1 in -[UIScrollView _didMoveFromWindow:toWindow:]() 
7 0x007a54bb in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
8 0x007a54bb in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
9 0x007a54bb in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
10 0x007af6d1 in -[UIScrollView _didMoveFromWindow:toWindow:]() 
11 0x007a54bb in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
12 0x007a54bb in -[UIView(Internal) _didMoveFromWindow:toWindow:]() 
13 0x007a1c72 in -[UIView(Hierarchy) _postMovedFromSuperview:]() 
14 0x007a04c6 in __UIViewWasRemovedFromSuperview() 
15 0x007a0141 in -[UIView(Hierarchy) removeFromSuperview]() 
16 0x009e69bb in -[UINavigationTransitionView _cleanupTransition]() 
17 0x009e6c86 in -[UINavigationTransitionView _navigationTransitionDidStop]() 
18 0x0079a499 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]() 
19 0x00799d6d in +[UIViewAnimationState popAnimationState]() 
20 0x007a326c in +[UIView(Animation) commitAnimations]() 
21 0x009e6702 in -[UINavigationTransitionView transition:fromView:toView:]() 
22 0x009e5ccb in -[UINavigationTransitionView transition:toView:]() 
23 0x008422b7 in -[UINavigationController _startTransition:fromViewController:toViewController:]() 
24 0x008423df in -[UINavigationController _startDeferredTransitionIfNeeded]() 
25 0x00842561 in -[UINavigationController __viewWillLayoutSubviews]() 
26 0x0095e4ca in -[UILayoutContainerView layoutSubviews]() 
27 0x007a8301 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:]() 
+0

是什麼時候崩潰日誌中說的? – AppHandwerker

+0

沒有什麼打印在日誌,但螺紋以下1所列出: #4 \t 0x00b0a8ab在 - [UIWebScrollView didMoveToWindow]() #5 \t 0x007a583e在 - [UIView的(內部)_didMoveFromWindow:toWindow:]() #6 \t 0x007af6d1在 - [UIScrollView中_didMoveFromWindow:toWindow:]() #7 \t 0x007a54bb在 - [UIView的(內部)_didMoveFromWindow:toWindow:]() #8 \t 0x007a54bb在 - [UIView的(內部)_didMoveFromWindow:toWindow:]( ) #9 \t 0x007a54bb在 - [UIView的(內部)_didMoveFromWindow:toWindow:]() 在#10 \t 0x007af6d1 - [UIScrollView中_didMoveFromWindow:toWindo W:]() 和更多 –

+0

我不明白,如果它與UIView層次結構或別的有關..請幫助我。 –

回答

0

我想你使用UIWebViewNavigationType條件和解決您的問題 試試這個: -

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 
     NSString *urlStr = [NSString stringWithFormat:@"%@", [request URL]]; 

     if ([[urlStr lastPathComponent] rangeOfString:@".jpg"].length) { 

      if (navigationType == UIWebViewNavigationTypeLinkClicked) 
      { 
       ThirdVC *controller = [[ThirdVC alloc] initWithNibName:@"ThirdVC" bundle:nil]; 
       controller setImageArr:self.imageDetailArr]; 
       [self.navigationController pushViewController:controller animated:NO]; 

      } 
      return NO; 
     } 
     return YES; 
    } 
+0

感謝您的快速回復elppa。但是無法將SecondVC視圖控制器(將其委託給UIWebViewDelegate)作爲secondVC.view作爲子視圖添加到FirstVC.view中。這就是爲什麼我使用Notification將其推向FirstVC。 –

相關問題