Only one cell could get user input - TableView - ios

I have three cells in my tableview which is standard tableview not custom cell. However, I would like the last cell to be editable, in other words I want that cell to get user input, something like textfield, but other cells just static and not editable.
I know how to make custom cell and make it work, but before I dive into that option I would like to know is there a tweak that I could use.
I wonder it is possible without making all tableview in custom cell?

You can use UITableViewHeaderFooterView instead of last cell. I think it is better way to add some UI into TableView.
You just need to override a method which is here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html#//apple_ref/doc/uid/TP40006942-CH3-SW22
There is a simple example here:
http://www.ioscreator.com/tutorials/customizing-headers-footers-table-view-ios7
I hope that is helpful for you.

Related

UITableView trigger when cell is reused

I'm having some issues with reusable cells in a UITableView. I have several types of cells, that I declare in the constructor.
My issue is that I have one particular type of cell that contains a UITextView and I have an issue when I scroll the table, the text within is lost. I need to save this text to the models that accompany the cells and then put the text back when the cell is used again.
How do I know that the cell is being moved away from? I have other types of cells, so I need a way to invoke some code to do the saving part on the scroll of the UITableView.
I hope that makes sense, if more is required, let me know.
Thanks.
Just save the text once it is changed to the model, check if any text is present and use that in tableView(_:cellForRowAt:)
For more help you will have to show us your code.
You can inherit UITextViewDelegate and in the textViewDidEndEditing(_:) check if the text view is edited, then you will be able to store the text in a variable or somewhere else and restore it whenever you are about to show that cell again.
If there is more than one text view, you might want to set an accessibility identifier for each kind, so you will find out which one did end editing.

How can I Create a Tableview Under Custom Tableview cell

I am just thinking. Suppose, i have a tableview which have custom cell. It's simple. But My idea is that, when i click a tableview cell then another tableview is appear under that tableview cell, and again i click that cell then that sub tableview disappear. Similarly when i click second cell than work same. Is it possible? Please Provide me any idea or reference.
This is entirely possible, you're talking about Expandable cells.
My example here
The general idea is that your custom cell has a tableview at the bottom of the cell, and what you do is just change the cell height to display said tableview, on tap.
It's not easy, I'm not gonna lie it took us a while to do it, but we managed, and I'm telling you, it's very possible.
You can find a lot of help using the Expandable Cell keywords.
Note that you're gonna find yourself handling a lot :
What to do when the expanding cells is shown off screen?
What to do when you're expanding the first/last cells ?
What to do when expanding another cell ?
What to do when scrolling inside that cell (a scrollview inside a scrollview !)
There are many cases where it'll work, but won't work fine, and there is gonna be a lot of fine tuning. Specially in our case where we have rounded corners, but only when the cell is expanded, and not in cases where it's the last or first cell (next to section header).
They look cool and make you feel proud, but don't say to your PM it'll be done in a week, because it's a pain to build.
If you want to show additional cell information, you can add more cells after the cell indexpath you have clicked.
Create a custom table view cell classCustomTableViewCell by subclassingUITableViewCell class. And system will generate CustomTableViewCell.h, CustomTableViewCell.m, CustomTableViewCell.xib files for you.
Add protocols UITableViewDataSource and UITableViewDelegate in your CustomTableViewCell.h and implement the required methods in CustomTableViewCell.m files
Add a method for setting datasource and use the datasource for updating the table.
NOTE:
Handle table-dequeue mechanism properly, otherwise you will end up
with weird issues that may take time to investigate and resolve.
If you use this custom cell for all the cells in your parent table then the gestures will only listened by the child table. So plan for that too.
Please visit my blog for the sample code. https://myioslearnings.blogspot.in/2017/03/nested-table-view-in-ios-objective-c.html

How to create 'containers' similar to Facebook?

I'm creating an app that will get data from an RSS feed and I want to know how I recreate something similar to the Facebook app 'containers'
An example of what I mean is below.
How would I go about recreating the boxes where the statuses are held?
To achieve your desire result you have to create custom table view cell using UITableViewCell and arrange views as per your need by creating subclass of UITableViewCell
Just create a UITableView with different prototype cells and then deque the appropriate cell identifier in cellForRowAtIndexPath.
You probably have to subclass UITableView for achieving the desired effects such as indentation etc.
After that you have to make custom view for each cell and return them from the method cellForRowAtIndexPath

iOS Maintaing selected button in Tableview when scrolling

I have a UItableView with custom cell. There are multiple sections, and in those sections multiple rows. In each cell, I have a segment button for "Yes" and "No" selections. I would like to maintain the selections for the segment button when I scroll up and down the table. Can anyone please help. I have looked and did not find anything that helped me. Thank you!
You have multiple ways to do this.
The first one, which I think is the best one, is to use the selected state for the uitableviewcell.
With this method, the table view it self will set the cell's state and according to that state will call didselect or diddeselect on its delegate. Since all is managed by the table view, you don't need additional logic on your cellForRow method, and don't even need to worry about cell reuse.
Another way is to always set the state of your cell's buttons in cellForRow. For this, you need to keep a reference to all the selected rows, and to be able to manage reused cells, you need to make sure its state is always set on cellForRow.
I prefer the first one, but whatever suits you better.

UITableView with multiple sections and a UIButton

I have a UITableView with two sections. Each section has a few UITableViewCells. I'd like to put a UIButton between the first section and the second section. Should the button be in it's own section? or perhaps in the third cell of the first section?
Edit #1: perhaps it's easiest to just use add another section with a single cell and style it like a button?
Well, that depends on how it's set up and how you want it to look. If you're in a plain table, I think it shouldn't really matter because there's no space between sections. If you're using a grouped table, it's probably easiest and best-looking to put the button in its own section.
You can put it in either its own section or in a cell. How you display the button visually (and its semantic meaning) might affect your choice.

Resources