更新iOS14后, collectionView、tableView无法点击的问题

更新前:   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 if(indexPath.section==0) {

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

        if(cell==nil) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

            UIView* viewBGTFD=[[UIViewalloc]initWithFrame:CGRectMake(60,10,DEF_SCREEN_WIDTH-80,40)];

            [viewBGTFDradiusBorderWithRadius:5 borderWidth:1 borderColor:[UIColor lightGrayColor]];

            [celladdSubview:viewBGTFD];

            _roomNameTFD= [[ZYTextFileldalloc]initWithFrame:viewBGTFD.bounds];

            if(self.isADDEdit) {

                _roomNameTFD.text=_modeRoom.name;


            }else{

                //查数据库排序最大到一个

                __block  NSInteger  sort_num;

                NSString *strsql=[NSString stringWithFormat:@"select max(sort_num) as maxvalue from room;"];

                [CoreFMDBexecuteQuery:strsqlqueryResBlock:^(FMResultSet*set) {


                    while([setnext]) {

                        sort_num=[setintForColumnIndex:0];

                        _roomNameTFD.text= [NSStringstringWithFormat:@"room%ld", (long)(sort_num+1)];

                    }


                }];


            }

            [viewBGTFDaddSubview:_roomNameTFD]; }        cell.textLabel.text=GDLocalizedString(@"名称");

        returncell;


    }else{

        AddRoomTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellAddRoom"];

        DeviceMode*mode=[_arrDataSourceobjectAtIndex:indexPath.row];

        cell.mode=mode;

        if(mode.favourite==1) {

            cell.btnStar.selected=YES;

        }

        returncell;

    }

}


更新后:   

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if(indexPath.section==0) {

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

        if(cell==nil) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

            UIView* viewBGTFD=[[UIViewalloc]initWithFrame:CGRectMake(60,10,DEF_SCREEN_WIDTH-80,40)];

            [viewBGTFDradiusBorderWithRadius:5 borderWidth:1 borderColor:[UIColor lightGrayColor]];

            [celladdSubview:viewBGTFD];

            _roomNameTFD= [[ZYTextFileldalloc]initWithFrame:viewBGTFD.bounds];

            if(self.isADDEdit) {

                _roomNameTFD.text=_modeRoom.name;


            }else{

                //查数据库排序最大到一个

                __block  NSInteger  sort_num;

                NSString *strsql=[NSString stringWithFormat:@"select max(sort_num) as maxvalue from room;"];

                [CoreFMDBexecuteQuery:strsqlqueryResBlock:^(FMResultSet*set) {


                    while([setnext]) {

                        sort_num=[setintForColumnIndex:0];

                        _roomNameTFD.text= [NSStringstringWithFormat:@"room%ld", (long)(sort_num+1)];

                    }


                }];


            }

            [viewBGTFDaddSubview:_roomNameTFD];

            [cell.contentViewaddSubview:viewBGTFD];

        }

        cell.textLabel.text=GDLocalizedString(@"名称");

        returncell;


    }else{

        AddRoomTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellAddRoom"];

        DeviceMode*mode=[_arrDataSourceobjectAtIndex:indexPath.row];

        cell.mode=mode;

        if(mode.favourite==1) {

            cell.btnStar.selected=YES;

        }

        returncell;

    }

}

总结:IOS14必须在cell的contentView上面添加控件: [cell.contentViewaddSubview:viewBGTFD];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容