ios - 尝试使用 Xcode 4.2 iOS 5 从 UIWebView 推送到详细 View

标签 ios xcode uiwebview ios5 storyboard

我在 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/

相关文章:

ios - UICollectionView 图像一次又一次加载,滚动滞后

ios - 如何在 MPMediaItemArtwork 中加载 URL 图片

iphone - 显示 UIMenuController 时获取选定的文本

iphone - 如何在 iPhone (iOS) 中暂停/恢复下载

ios - 如何跟踪定位服务是否启用?钛

ios - [UIViewController TableView :numberOfRowsInSection:]: unrecognized selector sent to instance

ios - 我可以在 Xcode 项目中使用 SVG 文件吗?

xcode - Xcode 5 会在优胜美地运行吗?

iphone - 如何将 NSURL fileURLWithPath 与片段一起使用?

ios - 使用 iOS UIWebView 时的 Rails 布局(application.html.erb)逻辑