ios - How to set contraints for self sizing UITableViewCell using Auto Layout in Interface Builder -


i have self-sizing tableviewcell presents comments. if current user commented present edit , delete buttons. contraints work in case. of constraints set in interface builder.

the challenge when comment doesn't belong user set .ishidden = true both edit , delete buttons. how can adjust constraints new scenario?

enter image description here

edit: issue when set .ishidden true on buttons, want cell height shrink button space empty.

another approach:

toggle .isactive state of constraint bottom of buttons bottom of cell, along .ishidden state.

to so, add vertical space constraint bottom of date label bottom of cell, set >= 4 (or "padding" want when buttons not there).

add @iboutlet spacing constraint bottom of edit button bottom of cell. in image, shows bottom = edit button.bottom + 2. when ctrl+drag constraint ib source file generate iboutlet line this:

@iboutlet weak var editbuttonbottomconstraint: nslayoutconstraint! 

you need edit line, though... constraints deallocated when deactivated, unless have "strong" reference it. so, remove weak modifier:

@iboutlet var editbuttonbottomconstraint: nslayoutconstraint! 

now, in cellforrowat, can do:

    cell.deletebutton.ishidden = !(comment.userid == appuserid)     cell.editbutton.ishidden = !(comment.userid == appuserid)     cell.editbuttonbottomconstraint.isactive = (comment.userid == appuserid) 

although, personally, make function inside cell.


based on cell design, though, i'm guessing commentslabel possibly / multi-line label? , you'll want cell expand vertically if comment is, say, 8 lines long? if so, still have few constraint relationships work out.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -