尝试使用UIWebView中的Xcode 4.2 iOS 5推送到详细视图 [英] Trying to push to detail view with Xcode 4.2 iOS 5 from UIWebView

查看:108
本文介绍了尝试使用UIWebView中的Xcode 4.2 iOS 5推送到详细视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入在NavigationController中的ViewController。 ViewController有一个UIWebView,我正试图从中捕获链接。我能够拦截链接,但是当我尝试将链接内容推送到详细页面时,它似乎正在触发一个新的控制器,但它是不可见的。如果我第二次点击链接(或者我只是点击第二个链接),我会看到弹出一个后退按钮,但新的ViewController的实际内容再次显示。

I have a ViewController embedded in a NavigationController. The ViewController has a UIWebView that I'm trying to capture links from. I'm able to intercept the links, but when I try to push the link content to a detail page, it seems to be firing a new Controller but it's invisible. If I click a link for a second time (or if I just click a second link) I see a back button pop up, but again the actual content of the new ViewController is not visible.

以下是第一个链接点击的日志输出:

Here is the log output for the first link click:

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'

如您所见,它正在加载新的查看,但我在模拟器中看不到任何内容。然后我第二次点击相同的链接(或点击一个新的链接)我在日志中看到这一点:

As you can see, it's "loading" the new view, but I see nothing in the simulator. Then the second time I click the same link (or click a new link) I see this in the log:

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顶部

Top of my SingleStoryViewController.m

#import "SingleStoryViewController.h"

@implementation SingleStoryViewController

@synthesize webView;

整个SingleStoryViewController.h
#import

Entire SingleStoryViewController.h #import

@interface SingleStoryViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

这是我的Xcode故事板图片的链接,为了它的价值: http://i.imgur.com/I653v.png

Here is a link to an image of my Xcode storyboard, for what it's worth: http://i.imgur.com/I653v.png

我现在已经工作了14到16个小时,我终于说'叔叔'并寻求帮助。任何帮助将不胜感激,我是iOS编程的新手,所以我很抱歉,如果有一些非常愚蠢的东西,我很遗憾。

I've been working on this for a good 14 to 16 hours now and I'm finally saying 'uncle' and asking for help. Any help would be appreciated, I'm very new to iOS programming so I apologize if there is something really stupid I'm missing.

推荐答案


如您所见,它正在加载新视图......

As you can see, it's "loading" the new view...

这不是错误说的是什么。错误说明了这一点:

That's not what the error says. The error says this:

Could not load NIB in bundle: [...] with name 'Detail View'

我首先检查应用中.xib文件的名称 - 听起来好像不是匹配您在代码中使用的名称。

I'd start by checking the name of the .xib file in your app -- it sounds like it may not match the name you're using in the code.

更新:根据以下评论,事实证明这是应用程序使用的故事板并且没有不包含任何.xib文件,因此尝试从.xib加载视图控制器会产生错误也就不足为奇了。必要时,从故事板加载视图控制器的正确方法是使用UIStoryboard的 -instantiateViewControllerWithIdentifier:方法而不是UIViewController的 -initWithNibName:bundle:

Update: Per comments below, it turns out that this is app uses storyboards and doesn't contain any .xib files, so it's no surprise that attempting to load a view controller from a .xib produces an error. The correct way to load a view controller from a storyboard, when necessary, is to use UIStoryboard's -instantiateViewControllerWithIdentifier: method instead of UIViewController's -initWithNibName:bundle:.

这篇关于尝试使用UIWebView中的Xcode 4.2 iOS 5推送到详细视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆