我在 NavigationController 中嵌入了一个 ViewController。 ViewController 有一个 UIWebView,我正试图从中捕获链接。我能够拦截链接,但是当我尝试将链接内容推送到详细信息页面时,它似乎正在触发一个新的 Controller ,但它是不可见的。如果我第二次单击一个链接(或者如果我只是单击第二个链接),我会看到一个后退按钮弹出,但是新 ViewController 的实际内容还是不可见。
这是第一个链接点击的日志输出:
2011-11-07 10:38:27.526 WGGB[43875:f803] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInternalInconsistencyException> Could not load NIB in bundle: 'NSBundle </Users/sonnyjitsu/Library/Application Support/iPhone Simulator/5.0/Applications/4B3D5152-4EA5-4C84-BB22-A774FCB8B6A7/WGGB.app> (loaded)' with name 'Detail View'
如您所见,它正在“加载”新 View ,但我在模拟器中什么也看不到。然后我第二次点击同一个链接(或点击一个新链接)时,我在日志中看到了这个:
2011-11-07 10:38:30.605 WGGB[43875:f803] url is http://www.blahblahblah.com/mobile
有问题的方法是这样的:
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange page = [ urlString rangeOfString: @"/mobile" ];
if (page.location == NSNotFound) {
SingleStoryViewController *detailViewController = [[SingleStoryViewController alloc] initWithNibName:@"Detail View" bundle:nil];
NSString *requestURL =
[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[detailViewController.webView loadRequest:
[NSURLRequest requestWithURL:[NSURL URLWithString:requestURL]]];
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(@"url is %@", url);
return NO;
} else {
return YES;
}
}
我的 SingleStoryViewController.m 的顶部
#import "SingleStoryViewController.h"
@implementation SingleStoryViewController
@synthesize webView;
整个SingleStoryViewController.h #导入
@interface SingleStoryViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
这是我的 Xcode Storyboard图像的链接,它的值(value):http://i.imgur.com/I653v.png
我已经为此工作了 14 到 16 个小时,我终于可以说“叔叔”并寻求帮助了。任何帮助将不胜感激,我是 iOS 编程的新手,所以如果我遗漏了一些非常愚蠢的东西,我深表歉意。
最佳答案
As you can see, it's "loading" the new view...
这不是错误所说的。错误是这样说的:
Could not load NIB in bundle: [...] with name 'Detail View'
我首先会检查您应用中 .xib 文件的名称——听起来它可能与您在代码中使用的名称不匹配。
更新:根据下面的评论,事实证明这是应用程序使用 Storyboard并且不包含任何 .xib 文件,因此尝试从 .xib 加载 View Controller 也就不足为奇了产生错误。必要时从 Storyboard加载 View Controller 的正确方法是使用 UIStoryboard 的 -instantiateViewControllerWithIdentifier:
方法而不是 UIViewController 的 -initWithNibName:bundle:
。
关于ios - 尝试使用 Xcode 4.2 iOS 5 从 UIWebView 推送到详细 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8038922/