不管是什么安卓還是IOS系統,都要進行不斷的升級,才能適應諸多廣大客戶,今天武林技術頻道小編帶給大家的是iOS11 SectionHeader 胡亂移動且滑動時出現重復內容的解決方法,趕快來學習吧!
問題描述:
-(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 胡亂移動且滑動時出現重復內容的解決方法,如果我們急用,暫時想不到其他辦法,可以套用本文的介紹后再進行改進。
新聞熱點
疑難解答