Put UITextView underneath undefined number of UITableViewCell's? - ios

I will have a number of cells (typically 5-6), and I want a text view underneath it. But I want the position of the text view to change based on the y-value of the lowest cell.
That way, no matter how many cells, the text view will be directly under the cells.
I tried placing the textview within the tableview, but it hid the cells.
Not sure what else to do.

you could for example set it as the tableFooterView...
(see https://developer.apple.com/reference/uikit/uitableview/1614976-tablefooterview)

Related

How to place UILabel exactly below UITableView?

I have UITableView with height of ≤500. Tableview data comes from database. Below UITableView, there is one label and two radio button. The problem is if data in the UITableView is less than its height, then it shows blank space between UITableView and those two radio button. I want to place those label and radio button exactly below tableview. How should I do this ?
This is how my tableview looks
If the table view's height does indeed vary depending on shown content, you could use UITableView's tableFooterView.
For a bit more context see this post for example.
Alternatively you could do this with basic auto-layout by tying your label and radio buttons (that you place as siblings of the table) vertically to the bottom of the table view.
I could also imagine that you may need a section footer. So you may want to have a look at that too.
If you want it to be scrollable, add it as the last row in your table view. You may also go with table view's footer.
If you want it to be sticky at the bottom in case of more rows, go with auto layouts. You may create outlet of table view's height constraint and adjust that accordingly depending on the number of rows. However, this approach is not appreciated.

Any way to dynamically adjust the height of a UITextView inside a UIStackView inside a UITableViewCell?

My situation: I have a UITextView inside of a UIStackView in a UITableView prototype cell.
After some research and coding, I've implemented the proper code for dynamic table row height adjustment by returning UITableViewAutomaticDimension in the heightForRowAt and estimatedHeightForRowAt delegate methods.
This works, but the problem is that this "dynamic" adjustment isn't dynamic enough. It only adjusts the height of the row to match the height of the UITextView after the UITextView's content is done being edited.
So my goal: to have this same adjustment occur whenever the text view expands dynamically to make all text in it visible, which it already does, yet the table cell doesn't expand with it while editing is still going on (at least I think that's what's happening, but I can't see the second line in the text view because the cell doesn't expand until editing is done).
The intuitive thing to do seems to be to use the textViewDidChange delegate method and to somehow equalize the row's height with the text view's height when text entry or removal results in the text view's height changing...
Yet I can't figure out what to put in there. I tried adjusting the .rowHeight and .estimatedRowHeight for my table view, but that doesn't seem to do anything while editing, neither with static height values nor with UITableViewAutomaticDimension.
Caveat: unlike most other questions about similar issues here on StackOverflow, in my case, the UITextView is inside a UIStackView, which means the stack view controls the size of the text view, and the table row in turn controls the size of the stack view via constraints, meanwhile, I've already gotten the text view to automatically resize to fit its contents, but the table row isn't resizing to match the text view's height while editing is still happening (at least that's the assumption, since I can't visually tell if the text view is expanding while editing is being done, or if it's just wrapping the text to a new line without actually adjusting its frame until editing is complete).
In short: table rows are only resizing to fit the text view/stack view inside them after text view editing is done because neither the table view's delegate methods nor manually setting .rowHeight and .estimatedRowHeight have any effect while a text view is being edited.
Any advice on how to get around this and get the table row and/or text view to resize while editing is happening would be much appreciated.
Turns out that just writing out that question in detail and then looking at a different question on StackOverflow allowed me to find one of several answers that described the solution to this predicament.
The answer:
func textViewDidChange(_ textView: UITextView) {
self.listTableView.beginUpdates()
self.listTableView.endUpdates()
}
Calling .beginUpdates() and .endUpdates() apparently calls the table view's delegate methods without breaking the editing process like .reloadData() does, allowing for truly dynamic table row height changes while editing a text view inside the table row.

How to make an effect of expandable UICollectionView cell in iOS

I have a collection view 3x3.
Item (collection cell) contains some icon and label.
I want some additional text to be shown inplace when user touches the cell. The view with this text must be fullscreen width.
In other words I want to insert a view with text between collection rows. It's desirable that the view appears with animation.
How should I do that? The first ideas I've got are:
Divide CollectionView rows into sections and use section footer for this purpose. Make this footer of zero size and show it when needed.
Dynamically create full-width cell and insert it at the end of the row where selected item is located.
Both methods seems tricky to me. Maybe there is more straight forward way?
Any ideas? Thanks!

How do I structure a table view to load halfway down a view?

I would like to make my UITableView load covering half of the window with a background view that starts visible, and as the window scrolls, is gradually covered by the table's cells.
Initially, I want to style is like so:
As the user scrolls, the cells will cover the background element.
The only way I could think to accomplish this would be to put the background element behind (and outside) a ScrollView (which is sized to fit over the background element and has a transparent background), put the TableView inside the ScrollView, and set the load coordinates to start the table far enough down. Is there a better way to accomplish my desired design?
I would prefer to avoid this layout because I would like to be able to easily add more cells dynamically as the user scrolls, ideally without having to deal with resizing the ScrollView.
You can take a view inside table view just above the table view cell and make its height whatever you want space in table view and make a outlet of that view. Then in view did load assign the view as table header view like this.
self.tableView.tableHeaderView = self.headerView;
This will be displayed exactly like you given and when user scrolls it will show the below cells and when you want you can change the frame of the header view and your header become invisible. You can do it whenever you want i mean if you want to change height on scrolling or if you want to change on adding more cells.

Number of Cell prototypes exceeds tableview height

I have a tableview that has a large number of fairly tall dynamic cells. I've tried creating the prototypes for these but I've run out of height room in the view.
I can't seem to extend the height of the table view, (or the view it's in). I also can't create the tableview outside the viewController, give it a larger height, and just link to it.
Suggestions? I know I can create the cells programmatically or from a separate nib, but I'd really like to do it via storyboard.
thanks,
Just figured this out myself. Try this:
Double-click the table almost anywhere except where there's an existing control. You can also double-click on the outer edge of the table.
Note that the table view will show a highlighted section that aligns with the cell you've clicked. You've entered some sort of selection mode.
Now use the mouse to scroll up or down. The cells will shift up or down as if you were running the app.

Resources