异常总结收录 - iOS

日常开发中所遇到的 Error 异常总结,方便日后快速解决.


一.tableview -> failed to obtain a cell from its dataSource

因为当前 cell 被调用早了,先循环使用 cell, 后又创建 cell,导致顺序错乱.

可能原因:

1.xib 的 cell 没有注册;

2.内存中已经存在这个 cell 的缓存(即:通过 cellId 所找到的 cell 并非当前想要的类型)

此时需要更改一下 cell 的标识.


二.cocoa pods -> unable to access 'https://github.com/facebook/pop.git':Operation timed out after 0 milliseconds with 0 out of 0 bytes received

可能是由于网络问题,网络请求超时,只需重试即可.


三.cocoa pods 出现 ERROR:While executing gem ... (Errno::EPERM)

解决办法:https://segmentfault.com/q/1010000002926243


四.no such file or directory:/users/apple/xxx

编译时此路径下无这个路径,首先需要检查缺少的文件是否在工程中;

若不存在与工程中,需从本地拖入;

若存在于工程中,或拖入工程中仍报错;

此时需要去 build phases 中搜索该文件夹,可能会通过搜索得到两个相同的文件夹结果;

其中,有一个路径是正确的,将错误路径删除即可;

若删除后仍不行,则需要将两个文件删掉,重新将文件导入进工程中即可.

异常总结收录 - iOS_第1张图片

五. no input file 

一般为工程路径变更,但项目文件设置的路径未改变所导致的问题.

首先,查看 pch 文件路径是否正常;

$(SRCROOT)/your project name/your project name-prefix.pch

其次,若无效则查看报错文件路径是否存在异常,例如.h & .m 是否出现 no input files,若出现则到项目下的 target --- build phases --- compile source 中,删除对应.h & .m文件后,重新将文件加入项目中;

最后,再次编译工程即可, command+B.


六.-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000c85

后台返回数据类型不匹配导致此原因.


七.declaration of ‘objc_property_t’ must be imported form module ‘ObjectiveC.runtime’ before it is required

即,需要包含头文件:

#import


八.error:linker command failed with exit code 1 (use -vto see invocation)

 -no_pie and -bitcode_bundle(Xcode setting ENDBLE_BITCODE=YES)cannot be used together;

这个bitcode是被编译程序的一种中间形式的代码。包含bitcode配置的程序将会在App store上被编译和链接。bitcode允许苹果在后期重新优化我们程序的二进制文件,而不需要我们重新提交一个新的版本到App store上。是xcode7之后更新的。在我们新建项目的时候默认是YES.如果我们的工程需要支持bitcode,则必要要求所有的引入的第三方库都支持bitcode

对于iOSbitcode是可选的。

对于watchOSbitcode是必须的。

对于Mac OSbitcode不支持。

解决:我们可以在”Build Settings”->”Enable Bitcode”选项中看到这个设置,并将它设置为NO.

解决:出现了两个完全一样的m文件,删除即可。(另外:如果代码中有c或者c++的混编,也不能在两个不同名称的mm文件中进行声明或者引用,这样也会触发这个错误的发生)


九.The operation couldn't be completed.(LaunchServicesError error 0.)

该问题原因为:修改了 Bundle ID.

解决:重启 iOS 模拟器即可.


十.Undefined symbols for architecture i386 error

原因:出现该报错一般是你使用当前模拟器作为目标,但编译的时候找不到相关的库文件所导致.

解决:需要将库文件所在的位置添加至 library search path 中即可.


十一.linker command failed with exit code 1

ld: warning: ignoring file /Volumes/Xcode/Xcode.app/Contents/Developer/Library/Frameworks/SenTestingKit.framework/SenTestingKit, missing required architecture armv7 in file

ld: duplicate symbolOBJC_METACLASS$_MMApiRegister in /Users/wangbin/Desktop/00_ios/hezi_ios08/WXSDK/libWeChatSDK.a(WeChatRegister.o) and /Users/wangbin/Desktop/00_ios/hezi_ios08/WXSDK/libWeChatSDK.a(WeChatRegister.o) for architecture armv7

clang: error: linker command failed with exit code 1 (use -v to see invocation)

这个问题不知道到底是什么回事...(貌似没适配 armv7)

解决:把.a 文件移除了,再重新添加.a文件 ,就编译过了.


十二.Xcode 真机调试错误:Could not find Developer Disk Image

 解决:

方法一:

将该文件拷贝至 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport,然后重新启动Xcode(完全退出 command+Q)即可.

方法二:

将当前 Xcode 版本进行提升.


十三.apple Mach-o Linker error 。

解决:通常为 compile source 中存在相同的 .m 文件.

"Build Settings" 中搜索 "compile source"


十四.真机调试出现 failed to get the task for process.

解决:该问题一般常为证书问题,检查当前证书是否过期或者存在不匹配等.


十五.expect a type

解决:可能出现在.h文件的循环引用,包含文件用@class代替即可。


十六.Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]

原因:就是函数- (UITableViewCell)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这个函数的返回值是个 null.

解决:检查 - (UITableViewCell)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

这个函数的代码逻辑。


十七.在link with lib种添加libxml2.dylb  后引用不了老是找不到头文件

解决:找到 Project->Edit Project Settings->Build Settings,把"/usr/include/libxml2"添加到 "Header Search Paths""-lxml2"添加到"Other Linker Flags


十八.虚拟机Xcode调试时候发现点击键盘出不来,命令行打印:

Can't find keyplane that supports type 8 for keyboard iPhone-Portrait-DecimalPad; using 3648623971_Portrait_iPhone-Simple-Pad_Default

解决:通过Hardware->Keyboard->Toggle Software Keyboard手动激活键盘.


十九.Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set

程序一运行就奔溃,但是我已经设置了storyboard的入口视图.而且storyboard名字是Main命令行打印

解决:为 StoryBoard 设置默认显示的 controller 即可.


二十.Null passed to a callee that requires a non-null argument

解决:其实错误发生在:

我错误地写成了 DISPATCH_QUEUE_PRIORITY_DEFAULT

正确应该 dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

从这里可以看出,Xcode的警告不能忽略,而且要先从英文去理解意思先;


二十一.local declareation “XXX” hide instance variable

解决:程序中有重名的变量,找出重名的变量并进行修改.


二十二.Cannot assign to 'self' outside of a method in the init family

源代码:

- (id) Myinit{  self = [super init];  ……}

解决:

- (id) initWithMy{  self = [super init];}


二十三.UIScrollView 无法滚动

可能原因:

(1)没有设置 contentSize

(2)scrollEnabled = NO

(3)没有接收到触摸事件: userInteractionEnabled = NO

(4)没有取消autolayout功能(如果在Storyboard中添加了ScrollView的子控件,要想scrollView滚动,必须取消autolayout).


二十四.App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

解决:在 iOS 9 beta1中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据.

需在 info.plist 中添加:

NSAppTransportSecurity -> NSAllowsArbitraryLoads


二十五. does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7

添加友盟时出现如上状况.

解决:由于Xcode自身的一些小问题,运行项目时一直报错 错误1的内容.然后我就检查项目友盟这个库的依赖呀.非常肯定的确认库已经导入而且在链接的二进制库里面.(就是build phases里面).然后就不断的重新导入clean了好多次还是不行.然后我就崩溃了.. 后来把Xcode重启再次运行真正的错误终于浮出水面(毕竟Xcode是beta版).就是错误2的内容.原来是友盟的二进制库不支持bitcode.而Xcode默认是要支持bitcode的,而且如果支持的话,其中所有的二进制库和framework都必须包含bitcode.


二十六.Unrecoginised selector sent to instance  ox6c11060

解决:控制台报这个错误,表示对象调用了一个不能识别的方法.




你可能感兴趣的:(异常总结收录 - iOS)