Swift UITableView在模拟器中工作正常,但在我的物理设备中工作不正常

Swift UITableView在模拟器中工作正常,但在我的物理设备中工作不正常,swift,uitableview,Swift,Uitableview,我目前正在开发一个应用程序,它显示了我学院所有可用的学院。我将数据保存在一个.plist文件中,我已在UITableView中读取并填充了该文件。我目前正在尝试在单元格中显示一些详细信息,如前缀和名称,单击该单元格可展开以显示有关教员的更多详细信息 我的TableViewController代码如下所示: struct-cellData{ var opened=Bool() var Name=String() var Prefix=String() var sectionData=[String

我目前正在开发一个应用程序,它显示了我学院所有可用的学院。我将数据保存在一个.plist文件中,我已在UITableView中读取并填充了该文件。我目前正在尝试在单元格中显示一些详细信息,如前缀和名称,单击该单元格可展开以显示有关教员的更多详细信息

我的TableViewController代码如下所示:

struct-cellData{
var opened=Bool()
var Name=String()
var Prefix=String()
var sectionData=[String]()
}
类TableViewController:UITableViewController{
//标记:-初始化变量
var dataManager=dataManager()
私有变量头=[String]()
私有变量facultyDetails=[[String:String]]()
var tableViewData=[cellData]()
@IBVAR facultyTableView:UITableView!
//MARK:-视图未加载
重写func viewDidLoad(){
super.viewDidLoad()
用于dataManager.allSheet1s()中的数据{
让dataInCell=cellData(opened:false,Name:data.item2!,
前缀:data.item1!,sectionData[data.item0!,
数据。项目2!,
数据。项目1!,
数据。项目3!,
数据。项目4!,
数据。项目5!,
数据。第6项!,
数据。第7项!,
数据。项目8!,
数据。项目9!,
data.item10!
])
tableViewData.append(dataInCell)
facultyTableView.register(UINib(nibName:“CustomCell”,bundle:nil),强制重用标识符:“CustomCell”)
}
}
//标记:-表视图委托
重写func numberOfSections(在tableView:UITableView中)->Int{
//#警告未完成执行,返回节数
return tableViewData.count
}
重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回1
}
重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
将cell=tableView.dequeueReusableCell(标识符为“CustomCell”)设为!CustomCell
如果indexath.row==0{
cell.EmpID.text=tableViewData[indexPath.section].sectionData[0]
cell.Name.text=tableViewData[indexPath.section].sectionData[1]
cell.Prefix.text=tableViewData[indexPath.section].sectionData[2]
cell.SchoolName.text=tableViewData[indexPath.section].sectionData[3]
cell.BuildingName.text=tableViewData[indexPath.section].sectionData[4]
cell.FloorNo.text=tableViewData[indexPath.section].sectionData[5]
cell.CabinLocation.text=tableViewData[indexPath.section].sectionData[6]
cell.RoomNo.text=tableViewData[indexPath.section].sectionData[7]
cell.CabinNo.text=tableViewData[indexPath.section].sectionData[8]
cell.intercommnumber.text=tableViewData[indexPath.section].sectionData[9]
cell.Email.text=tableViewData[indexPath.section].sectionData[10]
返回单元
}
返回单元
}
重写func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
如果tableViewData[indexath.section].opened==true{
tableViewData[indexath.section].opened=false
让sections=IndexSet.init(整数:indexPath.section)
tableView.reloadSections(节,带:。右侧)
}
否则{
tableViewData[indexath.section].opened=true
让sections=IndexSet.init(整数:indexPath.section)
tableView.reloadSections(节,带:。左)
}
}
重写func tableView(tableView:UITableView,heightForRowAt indexath:indexPath)->CGFloat{
如果tableViewData[indexath.section].opened==true{
返回400
}
否则{
返回70
}
}
}


现在你可以在模拟器中看到它工作得非常好。但当我将其加载到物理设备中时,行中每个单元格的高度都会通过其下方的其他单元格进行剪裁。

通过添加单元格修改单元格的行代码。clipsToBounds=true

   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomCell

        cell.clipsToBounds = true

        if indexPath.row == 0 {


            cell.EmpID.text = tableViewData[indexPath.section].sectionData[0]
            cell.Name.text = tableViewData[indexPath.section].sectionData[1]
            cell.Prefix.text = tableViewData[indexPath.section].sectionData[2]
            cell.SchoolName.text = tableViewData[indexPath.section].sectionData[3]
            cell.BuildingName.text = tableViewData[indexPath.section].sectionData[4]
            cell.FloorNo.text = tableViewData[indexPath.section].sectionData[5]
            cell.CabinLocation.text = tableViewData[indexPath.section].sectionData[6]
            cell.RoomNo.text = tableViewData[indexPath.section].sectionData[7]
            cell.CabinNo.text = tableViewData[indexPath.section].sectionData[8]
            cell.IntercomNumber.text = tableViewData[indexPath.section].sectionData[9]
            cell.Email.text = tableViewData[indexPath.section].sectionData[10]

            return cell
        }
       return cell
    }
并重写一个方法

   override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 70
    }

模拟器和物理设备是同一种iPhone类型吗?例如,模拟器是iPhone8,物理设备是iPhoneXR。在IB内部,您可以选择各种设备类型。模拟器是ios13 iPhone XR,物理设备是ios12.2 iPhone XR