【问题标题】:UIWebView not showing websiteUIWebView 不显示网站
【发布时间】:2014-09-21 12:58:44
【问题描述】:

我创建了一些用于显示网页的简单代码,自创建以来一直运行良好。但是,当我现在运行应用程序时,UIWebView 不再显示网页,尽管 NSLog 显示代码肯定正在运行。

在.h中:@property (weak, nonatomic) IBOutlet UIWebView *webView;

在.m中:

@synthesize webView;

- (void)viewDidLoad {
NSString *url = @"http://www.google.com";
[self createWebpage:url];

self.addressBar.delegate = self;

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void) createWebpage:(NSString *)webString {
    NSURL *url = [NSURL URLWithString:webString];
    NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:requestUrl];
    NSLog(@"Webpage is created!");
}  

我最近(不小心)删除了我创建的后退和前进 UIButtons 之间的引用插座。我这样说是为了以防它与问题有关。所有帮助表示赞赏。

编辑:我不知道为什么,但应用程序现在无法加载。它进入初始屏幕,然后出现错误,生成下面的错误日志。

2014-09-21 14:19:14.273 Fullscreen Ninja Browser for iPhone 6[6673:349224] Webpage is created!
2014-09-21 14:19:14.278 Fullscreen Ninja Browser for iPhone 6[6673:349224] *** Assertion failure in -[NSLayoutConstraint constant], /SourceCache/Foundation_Sim/Foundation-1140.11/Layout.subproj/NSLayoutConstraint.m:643
2014-09-21 14:19:14.283 Fullscreen Ninja Browser for iPhone 6[6673:349224] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105a073f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001056a0bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000105a0725a +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00000001052be28f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   Foundation                          0x000000010523a18d -[NSLayoutConstraint constant] + 170
    5   Foundation                          0x0000000105243ea3 -[NSLayoutConstraint _lowerIntoExpression:reportingConstantIsRounded:] + 197
    6   Foundation                          0x0000000105239dbe -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 96
    7   UIKit                               0x0000000106474495 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
    8   Foundation                          0x0000000105247a8e -[NSISEngine withBehaviors:performModifications:] + 155
    9   UIKit                               0x000000010647429b __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 452
    10  UIKit                               0x00000001064740ae -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 197
    11  UIKit                               0x0000000106473d21 -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] + 404
    12  UIKit                               0x0000000106468caf -[UIView(UIConstraintBasedLayout) _layoutEngine_windowDidChange] + 127
    13  UIKit                               0x0000000105e66d85 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 207
    14  UIKit                               0x0000000105e5f9c2 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 125
    15  UIKit                               0x0000000105e5f936 -[UIView(Hierarchy) _postMovedFromSuperview:] + 437
    16  UIKit                               0x0000000105e69835 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1550
    17  UIKit                               0x0000000105e37f43 -[UIWindow addRootViewControllerViewIfPossible] + 452
    18  UIKit                               0x0000000105e38152 -[UIWindow _setHidden:forced:] + 276
    19  UIKit                               0x0000000105e4465c -[UIWindow makeKeyAndVisible] + 42
    20  UIKit                               0x0000000105def191 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
    21  UIKit                               0x0000000105df1e5c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
    22  UIKit                               0x0000000105df0d22 -[UIApplication workspaceDidEndTransaction:] + 179
    23  FrontBoardServices                  0x00000001085a92a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    24  CoreFoundation                      0x000000010593cabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    25  CoreFoundation                      0x0000000105932805 __CFRunLoopDoBlocks + 341
    26  CoreFoundation                      0x00000001059325c5 __CFRunLoopRun + 2389
    27  CoreFoundation                      0x0000000105931a06 CFRunLoopRunSpecific + 470
    28  UIKit                               0x0000000105df0799 -[UIApplication _run] + 413
    29  UIKit                               0x0000000105df3550 UIApplicationMain + 1282
    30  Fullscreen Ninja Browser for iPhone 6 0x00000001051723c3 main + 115
    31  libdyld.dylib                       0x0000000107f7f145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

编辑 2:我发现当我“添加缺少的约束”到我的 UIButton 时,会导致上述错误。但是,当我清除约束时,应用程序运行良好,UIWebView 显示该站点。但是,按钮不合适,因为添加约束会导致应用程序崩溃,令人讨厌。有什么解决办法吗?

【问题讨论】:

  • 你确定你没有删除网页视图的出口吗?
  • 当我在 Interface Builder 中点击 UIWebView 时,它说在 webView 和 View Controller 之间有一个引用插座。
  • 您知道吗,您应该在使用任何视图或对您的 ui 执行任何操作之前调用 [super viewDidLoad]。这似乎是你的问题。
  • 我编辑了我的问题。该应用程序现在没有加载,所以我无法判断更改是否显示网页。

标签: ios objective-c nsstring


【解决方案1】:

在加载 webView 之前,您需要调用 [super viewDidLoad]
这应该有助于解决您的问题,

- (void)viewDidLoad 
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *url = @"http://www.google.com";
    [self createWebpage:url];
    self.addressBar.delegate = self;
}

【讨论】:

  • 应用程序现在根本没有加载:\ 不管我把超级。请查看我的编辑:)
  • 尝试删除应用,重启模拟器和Xcode,再次打开项目,在xcode中点击“cmd + K”,再次运行,希望对你有帮助。
  • 奇怪了,能把你的项目提交到github上吗?所以我可以运行并理解问题
  • 我通过创建一个新项目并逐渐复制所有内容发现了问题。当我向我的 UIButtons“添加缺少的约束”时,应用程序出错。但是,当我清除这些约束时,应用程序运行良好,除了我的按钮不合适......
  • 看来,这是autoLayout的问题,如果你不需要,请尝试禁用AutoLayouti.imgur.com/1zLg6DM.png
猜你喜欢
  • 1970-01-01
  • 2011-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多