国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS11 SectionHeader 胡亂移動且滑動時出現重復內容的解決方法

2019-10-21 18:43:52
字體:
來源:轉載
供稿:網友

升級到iOS 11后,痛苦的事情多起來了,以前版本沒有的出現問題的代碼,經過Xcode 9一編譯,千萬草泥馬奔騰而過;

今天碰到一個奇葩問題,直接進入主題:

問題描述:

-(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 會錯亂移動, 且調整tableView 的style也沒有效果;

2- 滑動tableView的時候, 貌似底部又多出一個圖層tableView,重復了tableViewCell的內容;

3-  以下代碼無效:(當然tableVIew 懶加載的時候 還有相應代碼設置cell分割線的偏移)

/** * 解決cell分割線距離兩邊12 居中對齊 */- (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)];  }}

最后排查發現:

舊代碼使用了xib但是又沒有用xib的tableView,  tableView又是自己代碼生成的, 把xib刪除之后,就OK了;

PS:下面通過實例代碼給大家分享UITableView SectionHeader 自定義section的頭部。

具體代碼如下所示:

//自定義section的頭部- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{  UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];//創建一個視圖  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;}

總結

以上所述是小編給大家介紹的iOS11 SectionHeader 胡亂移動且滑動時出現重復內容的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辉县市| 镇江市| 右玉县| 石狮市| 如皋市| 巨鹿县| 沾益县| 额尔古纳市| 隆林| 襄垣县| 呼伦贝尔市| 榆社县| 平凉市| 雷山县| 贡嘎县| 平陆县| 罗江县| 许昌市| 临桂县| 泸定县| 莒南县| 陵水| 秀山| 英德市| 镇江市| 阳新县| 武定县| 阿合奇县| 安西县| 宜君县| 达尔| 乌恰县| 宜兰县| 杭锦旗| 林口县| 酉阳| 永济市| 靖州| 淮阳县| 个旧市| 宜君县|