自己開發(fā)過程中遇到過很多錯(cuò)誤,但一直沒有整理記錄,今天開始遇到問題就整理記錄下,方便以后使用泪蔫。
一. cocoapods 添加第三方庫,第三方庫支持版本問題
ld: embedded dylibs/frameworks are only supported on iOS 8.0
and later (@rpath/AFNetworking.framework/AFNetworking) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我出現(xiàn)上面的情況注意是因?yàn)?用了 Cocoapods
安裝的第三方框架.
原因:
主要是因?yàn)閄XX的framework支持的最低開發(fā)環(huán)境為8.0
拂檩,而使用該framework的工程支持版本為8.0
以下
解決方法:
首先選中 pods
如圖:
然后修改支持的最低版本: 如圖:
二. 證書和id 不對應(yīng). 替換本地描述文件方法.
CodeSign error: code signing is required for product type
'Application' in SDK 'iOS 9.3'
原因:
簽名證書不對
解決方法:
-
>Build Settings -> Code Signing -> Code Signing Identity -> Debug -> Any ios SDK
將選項(xiàng)改為:iPhone Developer
- 如果上面還不對,就自己去網(wǎng)站上 看看對應(yīng)的ID和證書,描述文件是否都對.(我一般就直接去對id證書和描述文件.)
注意:
有時(shí)候你即使重新下載描述文件之后也還是錯(cuò)的,為什么呢,因?yàn)楸镜氐拿枋鑫募€沒有替換掉蠢莺。這種情況經(jīng)常出現(xiàn)在,新添加一個(gè)設(shè)備之后,要更新網(wǎng)上和本地的描述文件之后才能真機(jī)測試,這個(gè)時(shí)候老是提示描述文件找不到設(shè)備,這個(gè)時(shí)候就要?jiǎng)h掉原先的描述文件,替換成剛在網(wǎng)上下載下來的.具體步驟如下:
-
找到你要?jiǎng)h掉的描述文件,選中 點(diǎn)擊下面的
other
按鈕 如圖:
第一步 -
在彈出的框中,記住這一串字符.
第二步 -
打開
Finder
按快捷鍵command+shift+G
,在彈出框中輸入如下地址:/Users/youMacName/Library/MobileDevice/Provisioning Profiles
第三步 -
找到你剛才記住的那串字符,并刪除
第四步 再次打開
Xcode
快捷鍵command+shift+K
clean 一下項(xiàng)目,雙擊你重新下的描述文件,運(yùn)行,如果有別的錯(cuò),應(yīng)該就是下面記錄的第四個(gè)錯(cuò)誤4
,看看如何搞就行 ...
<br >
三. 真機(jī)測試 id 不對應(yīng)問題
The provisioning profile specified in your build settings
(“WeiDeveloper”) has an AppID of “xxx.xxx.xxx” which does not
match your bundle identifier “zzz.zzz.zzz”.
原因:
修改了證書和描述文件,對應(yīng)的id沒有替換,或者沒有替換全.
解決方法:
全局搜索 zzz.zzz.zzz
替換成 xxx.xxx.xxx
四. 更新 證書問題
Your build settings specify a provisioning profile with the UUID
“53cfe973-7bf2-414e-9942-f872469bb563”,
however, no such provisioning profile was found.
原因:
更換描述文件,出現(xiàn)的錯(cuò)誤,一般項(xiàng)目更換描述文件之后就會報(bào)這個(gè)錯(cuò)
解決方法:
- 關(guān)閉項(xiàng)目郎嫁,找到項(xiàng)目文件
XXXX.xcodeproj
吏口,在文件上點(diǎn)擊右鍵术瓮,選擇顯示包內(nèi)容
(Show Package Contents)。會新打開一個(gè)Finder踊东。 - 在新打開的
Finder
中找到project.pbxproj
北滥,并且打開,找到你所有包含報(bào)錯(cuò)的UUID‘XXX’
的行(一般有多行)闸翅,刪除再芋。 - 保存,重新啟動項(xiàng)目坚冀,再編譯济赎,就OK了。(一定要重新啟程xcode)
五. tableview 嵌套 collectionview 時(shí) item size 問題
CollectionView[62853:1528710] the behavior of the
UICollectionViewFlowLayout is not defined because:**
CollectionView[62853:1528710] the item height must be less
than the height of the UICollectionView minus the section insets
top and bottom values, minus the content insets top and bottom
values.**
CollectionView[62853:1528710] The relevant
UICollectionViewFlowLayout instance is
原因:
UICollectionViewFlowLayout
的itemSize
的寬或者高設(shè)置的有問題!它的size必須在父容器的范圍之內(nèi)司训!也就是說相等也不行构捡!我遇到這個(gè)警告主要是在UITableView
中嵌套了UICollectionView
,在tableview協(xié)議方法中heightForRowAtIndexPath
,和collectionview 協(xié)議方法中sizeForItemAtIndexPath
他倆設(shè)置的高度一樣.
解決方法:
在sizeForItemAtIndexPath
中調(diào)小高度,警告就沒有了.
六. 數(shù)組插入數(shù)據(jù)為nil
***** -[__NSArrayM insertObject:atIndex:]: object cannot be nil**
原因:
看意思就明白了,插入的元素為nil了
解決方法:
這個(gè)自己去找 ...... ??
七. xib 中出現(xiàn)多余連線
this class is not key value coding-compliant for the key new_logView.'
原因:
自己在xib中設(shè)置IBAction和IBOutlet時(shí)有多余的連線
解決方法:
找到錯(cuò)誤中提到的view,刪除多余的連線.
八: UIButton 加定時(shí)器 字體閃爍
iOS NSTimer定時(shí)刷新按鈕的文字,避免按鈕閃爍的辦法
錯(cuò)誤效果:
由于使用xib拖得視圖,沒有更換btn的類型.
解決方法:
將UIButton
的類型由system
改為custom
就OK
九: collectionview 的問題 下面?zhèn)z都是 插入/刪除/的時(shí)候出現(xiàn)的問題
Invalid update: invalid number of items in section 0. The number
of items contained in an existing section after the update (11)
must be equal to the number of items contained in that section
before the update (7), plus or minus the number of items inserted
or deleted from that section (1 inserted, 0 deleted) and plus or
minus the number of items moved into or out of that section (0 moved in, 0 moved out).
原因:
- 這個(gè)問題出現(xiàn)的時(shí)候頭疼了一會,因?yàn)槲铱创a怎么看怎么對,也是沒誰了.
后來才發(fā)現(xiàn)還是自己代碼的問題,最重要的一句話The number of items contained in an existing section after the update (11) must be equal to the number of items contained in that section before the update (7)
大概意思就是,更新前的數(shù)據(jù)源個(gè)數(shù)和更新后的不一樣了,更新前7個(gè),更新后11個(gè),發(fā)現(xiàn)代碼寫的有問題,我把刪除item的代碼,寫到else外面去了,先插入后刪除 ~ ~ ~ 本來應(yīng)該是插入就完事了,沒想又走了一個(gè)刪除的方法,先給自己一巴掌 ~~~?? - 還要說一種情況.當(dāng)你向一個(gè)空數(shù)組里面(個(gè)數(shù)為0的數(shù)組),調(diào)用
inster
方法,插入數(shù)據(jù)的時(shí)候,該數(shù)組個(gè)數(shù)不能為0 ~ 如果為0也會出現(xiàn)這個(gè)種情況~
解決方法:
把刪除的方法放到else里面就沒事了 ~~~
-
解決方法(當(dāng)要插入的數(shù)組個(gè)數(shù)為0時(shí),直接調(diào)用刷新方法) :
if (self.youList.count == 0 ) //要插入數(shù)據(jù)的數(shù)組 { [self.cusCollectionView reloadData]; }else { [self.cusCollectionView performBatchUpdates:^{ [self.cusCollectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:CUSTOM_SERVICE.selectedServiceId.count-1 inSection:0]]]; } completion:nil]; }
當(dāng)然出現(xiàn)這個(gè)問題的情況肯定是不一樣的,認(rèn)真閱讀下錯(cuò)誤信息,就可以.一般都是數(shù)據(jù)源在搞鬼~
<br >
十:
**reason: 'attempt to insert item 10 into section 0, but there are
only 10 items in section 0 after the update'**
原因:
我出現(xiàn)上面的錯(cuò)誤,是在使用collectionview過程中,向第0個(gè)section中,插入數(shù)據(jù)[self.cusCollectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:indexPaths]];
插入第10個(gè)元素,但是第0個(gè)section元素最多10個(gè),最大row值為9,所有奔潰.
解決方法:
后來發(fā)現(xiàn)是在插入前沒有及時(shí)更新源數(shù)據(jù).更新源數(shù)據(jù)之后問題就沒有了.
十一: 被除數(shù)為0的錯(cuò)誤提示
exc_arithmetic xcode (code = exc_i386_div,subcode = 0x0)
原因:
這種情況一般都是 被除數(shù)為0 . 有的時(shí)候看到這種錯(cuò)誤,是不是很頭疼壳猜?不知道該怎么辦呢 ~ (還是修為不夠,一直在路上~ ~ ~ )
解決方法:
找到報(bào)錯(cuò)的那行,看看被除數(shù)的數(shù)值.修改一下 ~
十二: 字符為nil
[NSNull componentsSeparatedByString:]: unrecognized selector sent to instance
原因:
返回的字符為nil或 "<null>" ,你調(diào)用字符轉(zhuǎn)數(shù)組的方法解析不了,所有報(bào)錯(cuò).
解決方法:
加好判斷,再處理~ 一般
if(![str isKindOfClass:[NSNull class] ] && str != nil)
十二:
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.
十三:
**reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'**
原因:
應(yīng)該是 初始化字典的時(shí)候value值為nil了,大部分都是@{key:value,key:value}
這種方式出現(xiàn)的錯(cuò)誤.
解決方法:
如果你還想用@{key:value,key:value}
這種方式最好先判斷value
是否為nil
,或者換其他的初始化方法,其它的一般value
數(shù)據(jù)為nil
的時(shí)候,不會添加到字典,取值的時(shí)候,盡量不要用[ ]
這種方式去取值,盡量使用objectForKey
即使取出來的值為nil
,也不會奔潰,只是一個(gè)nil
對象.
十四: cell 為nil
** 'UITableView (<ITTPullTableView: 0x7fc6620f3400; baseClass =
UITableView; frame = (0 64; 375 554); gestureRecognizers = <NSArray:
0x7fc663e29d30>; layer = <CALayer: 0x7fc663e291d0>; contentOffset:
{0, 0}; contentSize: {375, 3868.5074999988824}>) failed to obtain a cell
from its dataSource (<DCVoiceViewController: 0x7fc66302f600>)'**
原因:
出現(xiàn)這個(gè)錯(cuò)誤是加了一個(gè)新的cell
之后報(bào)的錯(cuò)誤,不加的時(shí)候是沒有錯(cuò)的,感覺是自己代碼寫的不規(guī)范.出現(xiàn)的原因是cell
為nil
,還去調(diào)用cell中的屬性并賦值
解決方法:
仔細(xì)查看代碼,加載cell
之前要判斷好cell
是否為nil
,如果不想判斷的話,建議實(shí)例化tableview
的時(shí)候使用如下方法加載 cell
這樣就不用再去判斷cell
是否為nil
:
- (void)registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
- (void)registerNib:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
- (void)registerClass:(nullable Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
十五 缺少庫文件
ld: library not found for -lcrypto
原因:
一般 lcrypto
和 -lssl
都是沒有找到 libssl.so,或第三方中的libssl.a文件
解決方法:
添加上庫就可以了.
十六 編譯報(bào)錯(cuò): ld: symbol(s) not found for architecture x86_64
原因:
-
缺少文件的引用,上圖就是缺少文件的引用
"_OBJC_CLASS_$_SkyServiceModel", referenced from:
這句話可以看出. - 還用一種可能是缺少文件,同上一樣
"_OBJC_CLASS_$_SkyServiceModel", referenced from:
可以看出.
具體是缺少哪一個(gè)就要自己在項(xiàng)目,查看并添加了 ~
解決方法:
自己去查看上文中提到的文件,是缺少引用還是文件.然后去修改.我這里是SkyServiceModel
是寫到一個(gè)manager
中,在.m
中沒有 @implementation SkyServiceModel
(啪啪,誰打的我好疼啊~)編譯的時(shí)候沒有通過才報(bào)的錯(cuò)誤.
十七 同時(shí)對同一個(gè)數(shù)組進(jìn)行了操作: Collection <__NSCFArray:0x7fb212429b10> was mutated while being enumerated.
原因:
舉例來說:
//錯(cuò)誤用法 (for arrayTemp 同時(shí)在里面對 它進(jìn)行 刪除操作)
NSMutableArray * arrayTemp = xxx;
for (NSDictionary * dic in arrayTemp) {
if (condition){
[arrayTemp removeObject:dic];
}
}
解決方法:
NSMutableArray * arrayTemp = xxx;
NSArray * array = [NSArray arrayWithArray: arrayTemp];
for (NSDictionary * dic in array) {
if (condition){
[arrayTemp removeObject:dic];
}
}
十八 數(shù)據(jù)庫語言錯(cuò)誤:
DB Error: 1 "near "": syntax error"*
DB Error: 1 "near "": syntax error"*
原因:
出現(xiàn)這種結(jié)果的話勾徽,主要是sql 語句識別出錯(cuò),或者是出現(xiàn)亂碼
可以打印出具體的sql語句來查找原因蓖谢。
栗子:
正確的語句:
insert into TEST (name, userId) values(@"中國", @"123")
錯(cuò)誤語句:
insert into TEST (name, userId) values(@"中國", @"*&^#$")
解決方法:
查看sql中是否有亂碼或內(nèi)容格式是否有問題.
十九 Reason: image not found
原因:
出現(xiàn)這種情況一般都是第三方庫找不到.
有人說把對應(yīng)的 framework 改為 optional 捂蕴,就可以運(yùn)行。但這是治標(biāo)不治本闪幽,代碼運(yùn)行到對應(yīng)的framework 引用的地方啥辨,還是會崩潰。
解決方法:
<br >
<br >
<br >