Reputation: 326
This is a broad question i know, and i basically ask this because i don't know how i would go about doing this. The task i have at hand is to make one generic tableViewCell that fit multiple purposes all at once and the layout of that cell will change accordingly to input. First of all, all cell must be able to have the following: A header, a body of text, a single image or multiple images, collection of data(displayed in UICollectionView inside UITableViewCell). The idea is that the user can create sections, these sections is of no type, so the task is to make the correct cell from this one generic UITableViewCell.
And example could be. A user create two sections- 1.Section the user creates a header and a body and nothing more. 2. Section the user create a body and multiple images. For section 1 the cell would only need to consist of a header and a body and ignore the rest. For section 2, i would have a body and some images. How would you guys go about creating this behavior? I tried using storyboard with constraints, but even though i hide the header the UIElement is still present and the body which is beneath the header constraints are still attached to the UIElement in case of section 2 where there is no header the body should have constraints to the top of the cell instead. Please ask me to rephrase if this is to broad or the idea is not visualize clearly enough.
Upvotes: 0
Views: 177
Reputation: 646
Anyway you define user source somehow, aren't you? So you have some kind of Model - struct which can fully define your UI behaviour, so I don't see any problems here if you know what combination of the fields which are valid and how they can be presented. Yeah, may be UI won't be easy but it will be 100 % defined
Upvotes: 0
Reputation: 1374
Try to look on stackview. Or if you do not want to use it, I do a simple trick.
Create one constraint to the top with priority 1. Add also one constraint for subtitle top to header bottom with priority 500. Create outlet for constraint with priority 1. Then whenever header title is set check if it is empty. If so set priority of constraint to 999 otherwise 1.
It is okay to use it for one element but in case of multiple elements it is better to use stackview.
Upvotes: 1