我的UINavigationController
包含UIViewController
(例如'FirstVC')。这个'FirstVC'包含UIScrollView
,在UIScrollView
的每一页上我添加了另一个UIViewCotroller
(比如'SecondVC')。此 SecondVC 包含具有多个链接的UIWebView
。我想推送另一个UIViewController
(比如'ThirdVC'),上面有UIScrollView
。但是当我尝试做同样的事情时,它会崩溃我的应用程序。
这是我申请的代码:
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的scrollView中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中,它列出了以下内容:
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 :(得分: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;
}