首页 - IOS编程

iOS开发错误提示汇总

1、

'UIWebView' is deprecated: first deprecated in iOS 12.0 - No longer supported; please adopt WKWebView.

从iOS 12开始不再支持UIWebView控件了, 替换成WKWebView即可

2、

Unknown type name 'WKWebView'; did you mean 'UIWebView'?

iOS8以后,苹果推出了新框架Webkit,提供了替换UIWebView的组件WKWebView。之前导入UIKit框架#import <UIKit/UIKit.h>不会有问题,现在必须再导入#import <WebKit/WebKit.h>

3、

"Could not instantiate class named WKWebView because no class named WKWebView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)"

无法初始化WKWebView,因为找不到WKWebView这个类

要想WKWebView这个类完成初始化,需要手动添加WebKit.framework

依次点击:Target(项目)——>Build Phases——>Link Binary With Libraries

展开,点击+,在打开的窗口搜索web,找到WebKit.framework选中添加即可

4、

-[__NSCFConstantString substringFromIndex:]: Index 9223372036854775807 out of bounds; string length 0

这个错误是使用substringFromIndex:这个方法的时候出现的

假如代码是这样写的

[source substringWithRange:range];
这个错误往往是source为空导致的,只要加个判断if(source.length !=0)再调用方法即可

另外多说一个

range的初始化应该这样写NSRange range = NSMakeRange(0, 0);

NSRange在初始化的时候如果用NSRange range;,没有指定range的初值,有时候就会出现这个错误—— Range {9223372036854775808, 18446744073709551615} out of bounds; string length 0 

5、

error build: SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0.

Build Setting中把Swift Language Version下改为Swift 4或者5即可

6、

[WindowScene] Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

原因分析:在StoryBoard中没有一个view controller设置了Initial Scene。

解决方案:在Storyboard中,选择一个view conroller作为story board的第一启动界面