gpt4 book ai didi

ios - 如何在 swift 3 的 TableView 单元格中从 super View 中删除时再次取回标签?

转载 作者:行者123 更新时间:2023-11-30 12:02:05 25 4
gpt4 key购买 nike

当没有可用地址仅显示一个标签时,我使用代码remove from superView从屏幕上删除标签,如下所示

enter image description here

但在这里,当我从 api 获取地址并且未正确显示时,输入的代码本身显示在图像中,如下所示

enter image description here

但是正确的图像应该显示姓名标签,地址标签和手机号码标签,任何人都可以帮助我如何在从API获取地址后从 View 中删除后显示地址标签和手机号码标签?

这是我的代码

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AddressTableViewCell
let dict = guestShippingAddressModel
self.tableDetails.isHidden = false
self.activityIndicator.stopAnimating()
self.activityIndicator.hidesWhenStopped = true
cell.deleteButton.tag = indexPath.row
if self.street?.isEmpty == true || self.street?.isEmpty == nil {
cell.addressLabel.isHidden = true
cell.mobileNumberLabel.isHidden = true
cell.radioButton.isHidden = true
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
cell.addresslabel.removeFromSuperview()
cell.mobileNumberlabel.removeFromSuperview()
cell.nameLabel.text = "No address available"
if delayCheck == true {
let when = DispatchTime.now() + 5 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let addtoCartVC = storyboard.instantiateViewController(withIdentifier: "newAddress") as! NewAddressViewController
self.navigationController?.pushViewController(addtoCartVC, animated: true)
}
}
}
else {
cell.addressLabel.isHidden = false
cell.radioButton.isHidden = false
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
cell.nameLabel.isHidden = false
cell.nameLabel.text = "\((dict?.firstName)!) \((dict?.lastName)!)"
cell.addressLabel.text = "\((self.street)!) \((dict?.city)!) \((dict?.region)!) \((dict?.postCode)!)"
cell.mobileNumberLabel.text = "\((dict?.telephone)!)"
}
cell.radioButton.tag = indexPath.row
cell.editButton.tag = indexPath.row
cell.deleteButton.tag = indexPath.row
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
cell.radioButton.addTarget(self, action: #selector(selectRadioButton(_:)), for: .touchUpInside)
cell.deleteButton.addTarget(self, action: #selector(deleteAction(button:)), for: .touchUpInside)
cell.editButton.addTarget(self, action: #selector(editButtonAction(_:)), for: .touchUpInside)
let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row)
if(checkIndex != nil) {
cell.radioButton.isSelected = true
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
}
else
{
cell.radioButton.isSelected = false
cell.editButton.isHidden = true
cell.deleteButton.isHidden = true
}
if (checkIsPaymentRadioSelect == true) {
let defaultvalue = street
if defaultvalue?.isEmpty == false {
cell.radioButton.isSelected = true
cell.editButton.isHidden = false
cell.deleteButton.isHidden = false
addressSelected = true
}
}
return cell
}

最佳答案

不要从 super View 中删除地址标签和移动标签,而是设置该标签的高度约束并将高度常量更改为 0 以隐藏标签并使单元格高度动态化,如下所示。

tblList.rowHeight = UITableViewAutomaticDimension;
tblList.estimatedRowHeight = CGFloat(100)

关于ios - 如何在 swift 3 的 TableView 单元格中从 super View 中删除时再次取回标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com