iOS開發(fā)中遇到的問(wèn)題

  1. tableview 或者 collectionview 點(diǎn)擊 cell 時(shí)不執(zhí)行 didselect 方法,原因有可能是因?yàn)楫?dāng)前 view 添加有 tap 手勢(shì),造成沖突.
    解決辦法:實(shí)現(xiàn)手勢(shì)代理,根據(jù)點(diǎn)擊的 view 確定是否響應(yīng)手勢(shì).
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    //cell 上有個(gè) label, 點(diǎn)擊 cell 的時(shí)候,實(shí)際點(diǎn)擊的是 label
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UILabel"]) {
        return NO;
    }
    return YES;
}

2.iOS 10,UIWebview 加載網(wǎng)頁(yè)的時(shí)候,底部會(huì)出現(xiàn)黑邊,加載完后黑邊消失,解決方法

self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor whiteColor];

3.terminate_handler unexpectedly threw an exception

1.對(duì)不可變對(duì)象進(jìn)行了改變
2.有可能是刪除了xib 中拉出來(lái)的屬性,但沒有對(duì)xib中的對(duì)應(yīng)控件刪除聯(lián)系

4.warning: directory not found for option“XXXXXX”

1.選擇工程, 編譯的 (targets)
2.選擇 Build Settings 菜單
3.查找 Library Search Paths 和 Framework Search Paths, 刪掉編譯報(bào)warning的路徑即OK

5.聲明數(shù)組屬性的時(shí)候最好用strong,如果用copy,那么對(duì)于可變數(shù)組(mutable array)

self.dataArray = [NSMutableArray arrayWithArray:@[@"1", @"2"]];
如果dataArray為可變數(shù)組,那么使用self.dataArray將得到一個(gè)不可變數(shù)組.

6.編譯警告:”no rule to process file ‘xxx.h’ for …."

解決方案:在[Build Phases] ->[Compile Source]里找到'xxx.h'文件刪除即可

7.編譯警告:This file is set to build for a version older than the project deployment target. Functionality may be limited
解決方案:選中xib文件,然后如下操作


20151106142334918.png

8.loaded the "XXXView" nib but the view outlet was not set.解決方案

1, 打開nib文件
2, 點(diǎn)擊"File's Owner", 按command+4,設(shè)置Class為xxxViewControler
3, 按Control+"Files's Owner", 里面有個(gè)默認(rèn)的IBOutlet變量view, 看一下后面有沒有做關(guān)聯(lián),如果沒有就拉到下面的View和視圖做個(gè)關(guān)聯(lián)

9.Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/B2624A21-58A9-487D-BC3F-96014EAEDD4E/CaiFuPai_swift.app> (loaded)' with name 'CurrentCell'

This error can occure when you rename some files outside XCode. 
To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference")
You re-import the files in your project and everything will be ok !

10.cell中有button的時(shí)候,滑動(dòng)的時(shí)候button上文字出現(xiàn)閃爍,把button的類型改為 custom 即可

11.“APP的名字” was compiled with optimization - stepping may behave oddly; variables may not be available.

出現(xiàn)這種信息多數(shù)是因?yàn)橘x值時(shí)某個(gè)值是 nil 造成的

12.自定義tableView的header

有時(shí)候我們想自定義UITableView的headerView,于是重寫代理方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
但是在運(yùn)行程序的時(shí)候發(fā)現(xiàn)該方法不執(zhí)行,這時(shí)我們還需要重寫一個(gè)代理方法:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
這個(gè)方法是用來(lái)指定headerView的高度的。

13.自定義rightitems時(shí),如果使用圖片,圖片會(huì)被渲染成藍(lán)色.解決辦法如下

UIBarButtonItem * weChatItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"im_weChat"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(copyWeChat)];
圖片不渲染,始終使用原圖
[[UIImage imageNamed:@"im_weChat"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
?著作權(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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