【问题标题】:Two uiwebview but only one works两个 uiwebview 但只有一个有效
【发布时间】:2013-09-03 10:23:47
【问题描述】:

我正在尝试使用情节提要实现 2 个 Web 视图,它们都链接到另一个在线网页。 出于某种原因,我没有收到任何错误,但只有 PriceViewController 有效。 其他VC生成白页……

我正在使用这 4 个文件:

PricesViewcontroller.h

#import <UIKit/UIKit.h>

 @interface PricesViewController : UIViewController

 {
     IBOutlet UIWebView *WebView; }

 @property (nonatomic, retain) UIWebView *WebView;

 @end

PricesViewController.m

 #import "PricesViewController.h"

 @interface PricesViewController ()

 @end

 @implementation PricesViewController @synthesize WebView;

 - (void)viewDidLoad {
    [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sparein.be/full_pricelist.pdf"]]];
      [super viewDidLoad];

 }


 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
         // Custom initialization
     }
     return self; }

 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated. }

 @end

ReservationsViewController.h

#import <UIKit/UIKit.h>

 @interface ReservationsViewController : UIViewController

 {
     IBOutlet UIWebView *WebView2; }

 @property (nonatomic, retain) UIWebView *WebView2;

 @end

ReservationsViewController.m

#import "ReservationsViewController.h"

 @interface ReservationsViewController ()
   @end

 @implementation ReservationsViewController @synthesize WebView2;

 - (void)viewDidLoad {
     [WebView2 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.be"]]];

     [super viewDidLoad];
     }


 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
         // Custom initialization
     }
     return self; }

 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated. }

 @end

【问题讨论】:

  • 实现UIWebViewDelegate 方法,也许他们可以告诉你正在发生的事情。
  • 确保您没有忘记从 ReservationsViewController 的 .xib 文件中引用 WebView2

标签: iphone ios objective-c uiwebview


【解决方案1】:

这可能无法解决您的问题,但试试这个。类似地更改您的PricesViewController.h 和ReservationsViewController.h。另外,你使用的是什么版本的 Xcode,你的目标是什么版本的 iOS?如果您使用的是最新版本的 Xcode 和 iOS,您的 .m 文件中不需要 @synthesize。

@interface PricesViewController : UIViewController

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

@end

IBOutlets 不应保留,因为这会导致保留周期。可能不是原因,但无论如何是良好的编程习惯。

【讨论】:

  • Xcode 版本 4.6.3,针对 iOS 6.1。删除@synthesize WebView;导致 WebViewloadRequest 出错
  • 再次检查 .xib 文件中的 UIWebView 出口是否连接到 .h 文件 IBOutlet。
  • 解决了!参考插座未连接。愚蠢的错误:-)。感谢大家的帮助!
  • 太棒了!很高兴我能帮上忙。如果愿意,请单击我的答案上的接受按钮。这将其标记为已接受的答案。谢谢!
猜你喜欢
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-28
相关资源
最近更新 更多