異常總結收錄 - 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 中搜索該文件夾,可能會通過搜索得到兩個相同的文件夾結果;

其中,有一個路徑是正確的,將錯誤路徑刪除即可;

若刪除后仍不行,則需要將兩個文件刪掉,重新將文件導入進工程中即可.


五. 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 <object/runtime.h>


八.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

解決:控制臺報這個錯誤,表示對象調用了一個不能識別的方法.




最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容