iOS11 SectionHeader 胡亂移動(dòng)且滑動(dòng)時(shí)出現(xiàn)重復(fù)內(nèi)容的解決方法
升級(jí)到iOS 11后,痛苦的事情多起來了,以前版本沒有的出現(xiàn)問題的代碼,經(jīng)過Xcode 9一編譯,千萬草泥馬奔騰而過;
今天碰到一個(gè)奇葩問題,直接進(jìn)入主題:
問題描述:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 12; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* headerSection_V = [[UIView alloc]initWithFrame:CGRectMake(ZERODIS, ZERODIS, SCREEN_WIDTH, 12)]; [headerSection_V setBackgroundColor:COLOR_3]; return headerSection_V; }
1- headerView 會(huì)錯(cuò)亂移動(dòng), 且調(diào)整tableView 的style也沒有效果;
2- 滑動(dòng)tableView的時(shí)候, 貌似底部又多出一個(gè)圖層tableView,重復(fù)了tableViewCell的內(nèi)容;
3- 以下代碼無效:(當(dāng)然tableVIew 懶加載的時(shí)候 還有相應(yīng)代碼設(shè)置cell分割線的偏移)
/** * 解決cell分割線距離兩邊12 居中對(duì)齊 */ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsMake(ZERODIS, 12, ZERODIS, 12)]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsMake(ZERODIS, 12, ZERODIS, 12)]; } }
最后排查發(fā)現(xiàn):
舊代碼使用了xib但是又沒有用xib的tableView, tableView又是自己代碼生成的, 把xib刪除之后,就OK了;
PS:下面通過實(shí)例代碼給大家分享UITableView SectionHeader 自定義section的頭部。
具體代碼如下所示:
//自定義section的頭部 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];//創(chuàng)建一個(gè)視圖 UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)]; UIImage *image = [UIImage imageNamed:@"4-2.png"]; [headerImageView setImage:image]; [headerView addSubview:headerImageView]; [headerImageView release]; NSString *createTime = [self.keysArray objectAtIndex:section]; createTime = [createTime stringByReplacingCharactersInRange:NSMakeRange(4, 1) withString:@"-"]; createTime = [createTime stringByReplacingCharactersInRange:NSMakeRange(7, 1) withString:@"-"]; UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 5, 150, 20)]; headerLabel.backgroundColor = [UIColor clearColor]; headerLabel.font = [UIFont boldSystemFontOfSize:15.0]; headerLabel.textColor = [UIColor blueColor]; headerLabel.text = createTime; [headerView addSubview:headerLabel]; [headerLabel release]; return headerView; }
總結(jié)
以上所述是小編給大家介紹的iOS11 SectionHeader 胡亂移動(dòng)且滑動(dòng)時(shí)出現(xiàn)重復(fù)內(nèi)容的解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
IOS textField限制字節(jié)長(zhǎng)度
這篇文章主要介紹了IOS textField限制字節(jié)長(zhǎng)度的相關(guān)資料,需要的朋友可以參考下2016-02-02iOS中幾種定時(shí)器的實(shí)現(xiàn)小結(jié)
這篇文章主要介紹了iOS中幾種定時(shí)器的實(shí)現(xiàn)小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01IOS 開發(fā)之UILabel 或者 UIButton加下劃線鏈接
這篇文章主要介紹了IOS 開發(fā)之UILabel 或者 UIButton加下劃線鏈接的相關(guān)資料,需要的朋友可以參考下2017-07-07iOS開發(fā)之image圖片壓縮及壓縮成指定大小的兩種方法
這篇文章主要介紹了iOS開發(fā)之image圖片壓縮及壓縮成指定大小的兩種方法,需要的朋友可以參考下2017-11-11iOS 仿微博客戶端紅包加載界面 XLDotLoading效果
這篇文章主要介紹了iOS 仿微博客戶端紅包加載界面 XLDotLoading,需要的朋友可以參考下2017-02-02iOS WKWebview 白屏檢測(cè)實(shí)現(xiàn)的示例
這篇文章主要介紹了iOS WKWebview 白屏檢測(cè)實(shí)現(xiàn)的示例,幫助大家更好的進(jìn)行ios開發(fā),感興趣的朋友可以了解下2020-10-10