ios - Hide UITableviewcell which contains UITextview (Autolayout) -


i have cell in tableview contains uitextview. uitextview has constraints of top, leading, trailing , bottom uitableviewcell content view. want hide uitableviewcell if textview contains empty text. that, reduce cell height 0. since textview has constraint set respect uitableviewcell.

  uitableviewcell --------------------------- |           -t-           | | -l-   uitextview  -r-   | |_________-b-_____________| 

l,t,b,r - left, top, bottom, right constraints

i getting constraints issue.

unable simultaneously satisfy constraints.     @ least 1 of constraints in following list 1 don't want.      try this:          (1) @ each constraint , try figure out don't expect;          (2) find code added unwanted constraint or constraints , fix it.  (     "<nslayoutconstraint:0x7fe5d58753a0 uitableviewcellcontentview:0x7fe5d5874fe0.bottommargin == uitextview:0x7fe5d399c000.bottom>",     "<nslayoutconstraint:0x7fe5d58753f0 uitableviewcellcontentview:0x7fe5d5874fe0.topmargin == uitextview:0x7fe5d399c000.top>",     "<nslayoutconstraint:0x7fe5d5888a20 'uiview-encapsulated-layout-height' v:[uitableviewcellcontentview:0x7fe5d5874fe0(0.5)]>" )  attempt recover breaking constraint  <nslayoutconstraint:0x7fe5d58753a0 uitableviewcellcontentview:0x7fe5d5874fe0.bottommargin == uitextview:0x7fe5d399c000.bottom> 

how can hide cell without having issue autolayout.

i turn constraints off , on using active property. simplest approach, note work on ios 8+, because active property on nslayoutconstraint added in ios 8.

first ensure have iboutletcollection array containing constraints need:

@iboutlet var allconstraints : [nslayoutconstraint]! 

you can hook them in xib/storyboard, if have one. otherwise set them in code.

then, in case want hide cell, do:

cell.allconstraints.foreach { $0.active = false } 

in tableview datasource method -cellforrowatindexpath:.

also, override -prepareforreuse: method on cell subclass follows:

override func prepareforreuse() {   super.prepareforreuse()   allconstraints.foreach { $0.active = true } } 

this turns constraints on, things behave correctly if hidden cell reused create non-hidden cell.

you may need add calls setneedslayout , layoutifneeded, i'd try without them start - layout pass triggered in table view's reloaddata should take care of things - it's best not call functions if don't need to.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -