iOS 常見(jiàn)錯(cuò)誤總結(jié)


一下內(nèi)容均為個(gè)人學(xué)習(xí)使用,有不足之處請(qǐng)拍磚。

使用代碼創(chuàng)建窗口,沒(méi)有反應(yīng),無(wú)法進(jìn)入 didFinishLaunchingWithOptions方法.

報(bào)錯(cuò)描述:使用代碼創(chuàng)建窗口,沒(méi)有反應(yīng),無(wú)法進(jìn)入 didFinishLaunchingWithOptions方法.

報(bào)錯(cuò)原因:沒(méi)有正確重寫(xiě)didFinishLaunchingWithOptions方法,或者修改錯(cuò)寫(xiě)了方法沒(méi)發(fā)現(xiàn)

解決方案:正確重寫(xiě)didFinishLaunchingWithOptions方法


reason: 'couldn't find a common superview for ...UILabel:0x7f8ec05c3ab0 frame = (0 0; 0 0);

報(bào)錯(cuò)原因 couldn't find a common superview for ... frame = (0 0; 0 0);使用masonry前沒(méi)有把對(duì)象加入父控件

解決方案:在masonry控制對(duì)象約束前把對(duì)象增加進(jìn)入某控件

[self.viewaddSubview:label];



Duplicate declaration of method ?錯(cuò)誤原因:復(fù)制方法的聲明(重復(fù)定義,重復(fù)聲明)

duplicate symbols for architecture ?錯(cuò)誤原因:重復(fù)導(dǎo)入.m文件或者錯(cuò)誤import? .m文件

解決方案:刪除相同的聲明,定義


Application windows are expected to have a root view controller at the end of application launch'

報(bào)錯(cuò)原因:沒(méi)有設(shè)置窗口的根控制器

解決方案:self.window.rootViewController= VC;//設(shè)置根控制器


Could not find a storyboard named 'main' in bundle NSBundle

報(bào)錯(cuò)原因:沒(méi)有找到名稱(chēng)為main 的storyboard ? 默認(rèn)是Main.storyboard

解決方案:UIStoryboard*storyboard = [UIStoryboardstoryboardWithName:@"main"bundle:nil];m改成大寫(xiě)


CUICatalog: Invalid asset name supplied: (null)

報(bào)錯(cuò)原因:Incompatible pointer types sending 'UIImage *' to parameter of type 'NSString * _Nonnull'

模型類(lèi)型與視圖使用模型設(shè)置數(shù)據(jù)時(shí)不匹配

解決方案: 檢查模型類(lèi)型,使得視圖對(duì)象里使用其時(shí)一致。


錯(cuò)誤描述 :? Static table views are only valid when embedded in UITableViewController instances

錯(cuò)誤原因 : 錯(cuò)誤的使用了talbe View的靜態(tài)cell , 靜態(tài)的cell只能在?UITableViewController 的實(shí)例對(duì)象 中使用

解決方案 : 使用動(dòng)態(tài)的cell ? ,在table View的屬性content 中選擇Dynamic prototypes


configureCellForDisplay:forIndexPath沒(méi)有綁定Identifier

錯(cuò)誤描述:-[UITableView _configureCellForDisplay:forIndexPath:]

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView后面一堆UITableView的屬性

錯(cuò)誤原因:沒(méi)有分配,綁定cellForRowAtIndexPath方法中對(duì)象cell的ID,導(dǎo)致對(duì)象沒(méi)有創(chuàng)建

解決方案:分配,綁定storyboard中tableViewCell的屬性ID同創(chuàng)建cellID


[約束警告] Unable to simultaneously satisfy constraints. 可能有重復(fù)約束

原因:系統(tǒng)自動(dòng)判斷 代碼 和 編輯器中可能有重復(fù)約束,可能會(huì)出錯(cuò)

Probably at least one of the constraints in the following list is one you don't want.

Try this:

(1) look at each constraint and try to figure out which you don't expect;

(2) find the code that added the unwanted constraint or constraints and fix it.

(

解決方案:修改某個(gè)對(duì)象約束的優(yōu)先級(jí)


setValue:forUndefinedKey:]:this class is not key value coding-compliant for the key xxxx

原因:模型的屬性和plist文件不匹配

根本原因:屬性缺失錯(cuò)誤key后面的XX ? ? ? ? //找屬性,數(shù)據(jù)類(lèi)型,基本數(shù)據(jù)類(lèi)型是不是多了*

1.找不到同名的plist數(shù)據(jù)和模型屬性

改正:修改plist或模型的名稱(chēng)保持一致

2.模型不是指針類(lèi)型的寫(xiě)了*號(hào)

改正:修改模型的類(lèi)型或者去掉*號(hào)

原因:xib文件沒(méi)有選擇(鏈接)視圖名稱(chēng) 導(dǎo)致模型給視圖賦值報(bào)錯(cuò)e.g.shopView.shop= shop;

解決方案:修改xib的Custom Class



報(bào)錯(cuò)描述:Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

報(bào)錯(cuò)原因:沒(méi)有設(shè)置指向控制器的箭頭 is Inital View Controller

解決方案:屬性頁(yè)面 View Controller 設(shè)置is Inital View Controller為YES


變量沖突 copyWithZone unrecognized selector sent to instance

報(bào)錯(cuò)描述:-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x7fff21746b20

報(bào)錯(cuò)原因 :屬性和變量名沖突

解決方案:修改屬性或者變量名


壞指針 使用代理方法時(shí)EXC_BAD_ACCESS

錯(cuò)誤描述:

錯(cuò)誤原因:寫(xiě)錯(cuò)了 讓代理執(zhí)行代理方法前的判斷語(yǔ)句,寫(xiě)成了執(zhí)行語(yǔ)句.

if([self.delegateperformSelector:@selector(addVC:andAdditem:)]) {

GLaddItem*additem = [GLaddItemaddItemWithName:self.nameTextF.textandNum:self.tellTextF.text];

[self.delegateaddVC:selfandAdditem:additem];

[self.navigationControllerpopViewControllerAnimated:YES];

}

解決方案:把performSelector方法改成respondsToSelector

if([self.delegaterespondsToSelector:@selector(addVC:andAdditem:)]) {

GLaddItem*additem = [GLaddItemaddItemWithName:self.nameTextF.textandNum:self.tellTextF.text];

[self.delegateaddVC:selfandAdditem:additem];

[self.navigationControllerpopViewControllerAnimated:YES];

}


壞指針 EXC_BAD_ACCESS? ? ? Conflicting return type in implementation of 'addItem': ‘?dāng)?shù)據(jù)類(lèi)型x' vs ‘返回值'

錯(cuò)誤描述: Conflicting return type in implementation of 'addItem': 'GLaddItem *' vs 'void'

運(yùn)行時(shí) , 訪(fǎng)問(wèn)變量時(shí) , 導(dǎo)致壞指針

錯(cuò)誤原因: 定義的方法名和變量名重復(fù)

解決方案:修改方法名或變量名稱(chēng)


loaded the ’xxx’ view outlet was not set

錯(cuò)誤描述'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "GLEditController" nib but the view outlet was not set.'

報(bào)錯(cuò)原因:通過(guò)xib描述的控制器沒(méi)有連續(xù)view

解決方案: 在xib中連接Owner的view


Incompatible pointer to integer conversion assigning to 'UITableViewCellSeparatorStyle' (aka 'enum UITableViewCellSeparatorStyle') from 'UISwitch *'

提示 賦值不正確,對(duì)象應(yīng)該是個(gè)枚舉值


isEqualToString,length 模型類(lèi),模型對(duì)象使用混亂

-[GLWine isEqualToString:]

-[GLWine length]: unrecognized selector sent to instance

錯(cuò)誤原因:賦值了不正確的對(duì)象 模型數(shù)組里面是模型類(lèi)對(duì)象,不是模型對(duì)象

解決方法:先創(chuàng)建模型類(lèi)對(duì)象,再使用模型對(duì)象

GLWine*wine =self.wines[indexPath.row];

cell.imageView.image= [UIImageimageNamed:wine.image];


字典轉(zhuǎn)模型沒(méi)有值,報(bào)錯(cuò)[__NSCFString objectForKeyedSubscript:] [__NSCFDictionary length]

沒(méi)有值:

1.控制器重寫(xiě)模型數(shù)組的get方法中首先沒(méi)有初始化數(shù)組

_wines= [NSMutableArrayarray];沒(méi)初始化添加的對(duì)象為空null

2[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance

[__NSCFDictionary length]: unrecognized selector sent to instance

Incompatible pointer types assigning to 'NSString *' from 'NSDictionary *'

報(bào)錯(cuò)原因:沒(méi)有寫(xiě)完整字典,注意在模型對(duì)象中用字典賦值的字典書(shū)寫(xiě)完整性,forin一般是遍歷數(shù)組,

解決方法:檢查字典書(shū)寫(xiě)完整性,并根據(jù)數(shù)據(jù)源(plist或網(wǎng)絡(luò))修改

tip提示:若是字典里dict[@"cars”]字典key輸入不正確,只會(huì)導(dǎo)致沒(méi)有數(shù)據(jù)然而不會(huì)報(bào)錯(cuò).


tableView代理對(duì)象沒(méi)有實(shí)現(xiàn)方法

[ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

0.代理對(duì)象沒(méi)有聲明對(duì)應(yīng)的協(xié)議

Assigning to 'id _Nullable' from incompatible type 'ViewController *const __strong'self.tableView.dataSource=self;或者拖線(xiàn)給控制器(其他代理對(duì)象)

1.代理對(duì)象沒(méi)有實(shí)現(xiàn)必須實(shí)現(xiàn)的協(xié)議方法1

Method 'tableView:numberOfRowsInSection:' in protocol 'UITableViewDataSource' not implemented

2.代理對(duì)象沒(méi)有實(shí)現(xiàn)必須實(shí)現(xiàn)的協(xié)議方法2

Method 'tableView:numberOfRowsInSection:' in protocol 'UITableViewDataSource' not implemented-[ViewController tableView:numberOfRowsInSection:]

3.代理對(duì)象沒(méi)有實(shí)現(xiàn)必須實(shí)現(xiàn)的協(xié)議方法3Method 'tableView:cellForRowAtIndexPath:' declared here

-[UITableView _configureCellForDisplay:forIndexPath:]

解決方法 必須實(shí)現(xiàn):

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView//不實(shí)現(xiàn)返回1

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

-(UITableViewCell*)tableView


寫(xiě)錯(cuò)標(biāo)點(diǎn)

報(bào)錯(cuò):? Expected ‘]’ or ‘,’

原因: ?1.數(shù)組連接符號(hào)用錯(cuò) ? ? ? ? ? ? ? ? ? ? ? ? ? ? 解決方案:需要用 , 逗號(hào)鏈接

2.數(shù)組最后一個(gè)元素寫(xiě)了連接符號(hào) ? ? ?? 解決方案:去掉最后一個(gè)元素后的連接符號(hào)

3.Expected ‘;’ after expression ?簡(jiǎn)寫(xiě)數(shù)組,最后沒(méi)有寫(xiě)分號(hào) ? ? 解決方案:加上語(yǔ)句結(jié)束符號(hào) ;


約束錯(cuò)誤

Unable to simultaneously satisfy constraints.

Probably at least one of the constraints in the following list is one you don't want.

Try this:

(1) look at each constraint and try to figure out which you don't expect;

(2) find the code that added the unwanted constraint or constraints and fix it.

無(wú)法同時(shí)滿(mǎn)足的約束。

可能至少在以下列表中的約束之一是一個(gè)你不想要。

試試這個(gè): (1) 看看每個(gè)約束和試著去弄了,你不會(huì)指望;

(2) 找到添加不必要的約束或限制的代碼并修復(fù)它。

錯(cuò)誤原因1://把A對(duì)象的底部等于B右邊,對(duì)應(yīng)連線(xiàn)找不到

make.bottom.equalTo(blueView.right);

錯(cuò)誤原因2://同一個(gè)對(duì)象重復(fù)寫(xiě)了同一個(gè)約束

make.top.equalTo(blueView.top);

make.top.equalTo(blueView.bottom);


Could not load NIB in bundle with name XXX

原因reason: 'Could not load NIB in bundle: 'NSBundle 找不到要讀取的nib

(loaded)' with name 'GLshopView''

解決方案:把xib的名字改成何視圖類(lèi)名一樣


Auto property synthesis will not synthesize property 'title'; it will be implemented by its superclass, use @dynamic to acknowledge intention

錯(cuò)誤原因:自動(dòng)屬性合成不會(huì)合成屬性title;它將由它的超類(lèi),使用承認(rèn)意圖 @dynamic 執(zhí)行

UILabel...title

改正:UILabel不要使用title 作為屬性標(biāo)識(shí)符


No visible @interface for 'NSArray<__kindof UIView *>' declares the selector ‘removeLastObject'

錯(cuò)誤原因:NSArray是不可變數(shù)組 不能使用刪除最后一個(gè)元素

解決方案:使用NSMutableArray 或者[self.shoptable.subviews.lastObjectremoveFromSuperview];


-[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'

-[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]' -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'

index 0 beyond bounds for empty array

錯(cuò)誤原因:數(shù)組下標(biāo)越界了

解決方案:打印檢查數(shù)組的個(gè)數(shù),并根據(jù)需要修改


unrecognized selector sent to instance

原因:調(diào)用了一個(gè)不存在的方法,方法被刪掉/注釋/名稱(chēng)修改

解決:認(rèn)真檢查方法名,使用正確并且存在的方法名


not key value? for the key... 多余連線(xiàn)

原因:IBOutlet屬性代碼被刪掉/注釋了,但是屬性連線(xiàn)還在

根本原因:屬性缺失錯(cuò)誤key后面的XX ? ? ? ? //找屬性

解決:將storyboard殘留的連線(xiàn)刪掉,或在把線(xiàn)連上


Receiver type 'NSTextAlignment' (aka 'enum NSTextAlignment') is not an Objective-C class

錯(cuò)誤原因 :is not an Objective-C class屬性返回值是個(gè)枚舉,后面寫(xiě)了個(gè)類(lèi)調(diào)用方法

解決方案:直接寫(xiě)枚舉值

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容