iOS 소규모 기술: UITableView 적응(iOS10/iOS14/iOS16.0)

이 글은 "골든스톤 프로젝트" 에 참여하고 있습니다.

소개

개발 사양에 따라 코드를 작성하면 UITableView에 대한 적응 문제가 없을 것입니다.

  • 사양에 맞게 UITableViewHeaderFooterView를 사용하면 iOS16 가로 세로 화면 전환 장면의 바닥글 문제는 없을 것입니다.
  • 사양에 따라 UITableViewCellContentView에 UITableViewCell의 하위 뷰를 추가하면 iOS14에서 차단되는 문제는 없을 것입니다.
  • tableView:viewForFooterInSection:the 및 t 메서드를 모두 ableView:heightForFooterInSection:주석 처리하면 heightForFooterInSection 높이가 0을 반환하더라도 iOS10에서 뷰를 표시하는 데 문제가 없습니다.

I iOS16.0 가로 세로 화면 전환 적응

화면 전송 메서드를 호출한 후 뷰는 프레임을 다시 업데이트해야 합니다.

1.1 현재 화면 가로 세로 화면 상태 가져오기

  • (UIInterfaceOrientation)interfaceOrientation {// 현재 화면 상태 가져오기 if (@available(iOS 13.0, *)) { return [UIApplication sharedApplication].windows.firstObject.windowScene.interfaceOrientation; } return [[UIApplication sharedApplication] statusBarOrientation]; }

1.2 iOS16.0에서 화면 전송 방식 조정 후 뷰의 프레임을 다시 업데이트해야 하는 문제

문제: 전자 서명 인터페이스에서 돌아온 후 바닥글의 프레임이 올바르지 않습니다.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
        UIButton *nextBtn = [ControlManager getButtonWithFrame:CGRectMake(KWratio(30), KWratio(25), kWidth - KWratio(60), KWratio(45)) fontSize:displayFontSize(15.0f) title:@"提交" titleColor:[UIColor whiteColor] image:[UIImage new] backgroundColor:BASE_RED_COLOR cornerRadius:KWratio(5)];
return xxx;
}
复制代码

이유: iOS16.0에서 화면 전송 방식을 호출한 후 자동 레이아웃을 사용하지 않는 경우 뷰에서 프레임을 다시 업데이트해야 합니다.

해결 방법: 바닥글 및 머리글 사용자 지정(titleForHeaderInSection 대신 UITableViewHeaderFooterView)

1.3 맞춤 바닥글

UITableViewHeaderFooterView 대신 titleForHeaderInSection

blog.csdn.net/z929118967/…

  1. FooterView 등록
        [_tableView registerClass:[CRMNextBtnHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"CRMNextBtnHeaderFooterView"];
复制代码
  1. FooterView 반환
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    CRMNextBtnHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"CRMNextBtnHeaderFooterView"];

//    footerView.models = self.viewModel.passwordRuleDescModel;

    return footerView;
}
复制代码
  1. FooterView 구현

@interface CRMNextBtnHeaderFooterView : UITableViewHeaderFooterView

@property (nonatomic , weak) UIButton *nextBtn;

@property (nonatomic , weak) UIButton *cancelBtn;


@end
复制代码

II UITableViewCell 호환성 문제 해결(iOS14 적응)

kunnan.blog.csdn.net/article/det…

2.1 문제 분석

iOS14 UITableViewCell의 하위 시도는 클릭이나 슬라이딩 등의 제스쳐에 반응하지 못하며, 문제가 있는 셀은 기본적으로 Cell에 직접 추가되는 것으로 확인되었으며, Xcode와 함께 제공되는 DebugViewHierarchy 뷰의 분석을 통해 문제는 시스템과 함께 제공되는 UITableViewCellContentView에 의해 차단된다는 것입니다.

2.2 솔루션

변경해야 할 관행

cell.contentView.addSubView(tempView1)
复制代码

글로벌 수정 적응

//
//  UITableViewCell+CRMaddSubView.m
//  Housekeeper
//
//  Created by mac on 2020/9/18.
//  Copyright © 2020 QCT. All rights reserved.
//

#import "UITableViewCell+CRMaddSubView.h"

@implementation UITableViewCell (CRMaddSubView)
+ (void)load {
    // Swizzle addSubView
    [UITableViewCell sensorsdata_swizzleMethod:@selector(addSubview:) withMethod:@selector(kunnan_addSubview:)];
    
}

- (void)kunnan_addSubview:(UIView *)view {

    
    
    if  ([view isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) {//允许 addSubView UITableViewCellContentView 
        
        [self kunnan_addSubview:view];//实现方法,因为已经进行了 swizzle,相当于调用原来的方法
        

        
    } else {//
        
        [self.contentView addSubview:view];
        
    }



}



@end
复制代码

III iOS10 시스템에서 UITableView의 적응 문제

기본적으로 현재 iOS10용 실제 장치가 없기 때문에 시뮬레이터를 다운로드하여 iOS10을 테스트할 수 있습니다.

  1. tableView numberOfRowsInSection:QCTReceiptsubFilterViewSection4KeyTypeTitle]사용법의 실행 순서는 iOS10에서 매우 특별하며 메서드에서 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section호출 . 그렇지 않으면 무한 루프가 발생합니다.
  2. iOS10의 heightForFooterInSection은 높이가 0을 반환하더라도 보기를 표시합니다.

3.1 프록시 메서드의 실행 순서

tableView:numberOfRowsInSection메서드에서 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 호출 . 그렇지 않으면 무한 루프가 발생합니다.

3.2 테일 뷰 표시

iOS10에서 viewForFooterInSection을 표시하지 않는 올바른 방법은 tableView:viewForFooterInSection:및 t ableView:heightForFooterInSection:메서드를 모두 주석 처리하는 것입니다.


//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    
//    return 0;
//    
//    return kAdjustRatio(92+10);
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//     *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@""];
//    
//    footerView.type =  self.type;
//    footerView.models = self.viewModel.datas[section];
//    return footerView;
//}
复制代码

рекомендация

отjuejin.im/post/7210658541212565562