简体   繁体   中英

Swift :How can i remove the outlets from code?

I have a height outlet for a view. It is set to 55.In a tableview i have used it. Some where i require a static height and some where it does not require a height. So i want to remove this static height from my code.How can i achieve this?is it possible?

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        if(heightIsStatic.count> 0)
        {
     //here i require a static height and is working fine as height can   
     //be printed as 55
        }
        else
        {
            self.ViewHeight.active = false
            print(self.ViewHeight.constant)
        }
    }

Even i have set active to false it is still showing static height constraint.Can i remove that static height in else case??

If you want the dynamic size for else part then you have to remove outlet of constraint then in your code you have to find the constraint and then change it's constant or remove if needed

for constraint in view.constraints {
    if(constraint.firstAttribute == NSLayoutAttribute.height)
    {
         constraint.constant = 55
    }
}

If I understood your question correctly, pls try this (assuming the constraints for your cells are correct)

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
 if (indexPath.row == 1) { //change this with the row number
  return 55.0
 }

 return UITableViewAutomaticDimension
}

Pls comment if you dont have a specific row and I will edit my answer. Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM