更新前: - (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];