我创建了一些设计用于显示网页的简单代码,自创建以来,该网页一直运行良好。但是,当我现在运行应用程序时,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显示该站点。但是,按钮不合适,因为添加约束导致应用程序崩溃,令人讨厌。任何解决方案?
答案 0 :(得分:0)
在加载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;
}