header cell on top of list - uitableview

I have a tableview with a list. I want to add a cell to the top of the list that shows what is being displayed below. So each item in the list is a Name with Age and Gender next to it. I want a header cell on top that actually says "Name Age Gender" so that people actually know what data is being displayed. I also want this cell to not scroll when the rest of the list scrolls downwards.
Do I add another cell to show these things or should I do it via another method?

I think you're talking about a header of a table view section. If so, you can implement the header cell methods in UITableViewDataSource:
-tableView:titleForHeaderInSection:
Alternatively, if you want to get fancy and use your own view for a section header try implementing the UITableViewDelegate method:
-tableView:viewForHeaderInSection:

Related

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

set height of outer TableViewCell from inner nested UITableViewCell

I'm trying to implement accordion view using UITableView. I want nesting of the view up to 2 levels.
(Example : There are multiple Regions under Each Region there will be zero/multiple Locations and under Each Location there will zero/multiple Users).
For implementing this scenario I used nested UITableView. i.e Outer TableView (i.e Region TableView) will have its cell as another UITableView (i.e Location TableView) and Each cell of LocationTableView will have another UITableView(i.e TableView Showing users list under each location) as its cell.
I have attached the images for more clarification.
In below image Regions are sections of the tableview. (note : not a single row for now in tableview)
After Tapping 2nd section i.e section with name Region I dynamically reload that section and add the cell(i.e the cell that contains the UITableview showing the locations)
But, it shows the empty space below the location tableview.
Instead I want something like this as below :
Again after tapping the 0th section(Location 0) of the inner tableview (i.e tableview containing location list) I dynamically reload that section of tableview and add the cell(i.e the cell that contains the UITableview showing the list of users under that location)
Have a look at below image
It works perfectly.
Now my issue is that I have calculated the height of the outer UITableviewCell in *- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath )indexPath method depending on the number Location within That Region(i.e Cell) and number of Users under each Location under that Particular Region cell. Issue is that I need to hide/show the locations and users list(All the locations and users list is not shown at once)as according to accordionView. So the height of the inner tableView increase/decrease, hence leaving the blank space at the bottom. Also I have created custom UITableViewCell (i.e creating separate nib file for the cell) for each inner cell containing tableview as ContentView and implemented all the UITableView Data Source and Delegate methods in its corresponding .m file.
What I want is not to show that empty blank space.
When control goes in the inner tableview cells I can't set the height of the outer UITableView from there.
Hope you understood my problem. Please help me. Thank you!!!
I had some similar requirements like this, I didnt use the nested tableview as it brought some complexities to me, so I tried playing around with indentation and indexpaths of the tableview to achieve what I wanted. I just did a small sample app with that concept with some dummy data. I have never tried this approach with Custom cells. See if this helps.
I know I am not answering to the exact question that you asked but I am trying to give a different approach which for me looked simpler.
I just modified my base code to match your data
How to create an Accordion with UItableview under a UItableview?
The source can be found here
Accordion
Screenshot
-anoop

How to distinguish between UITableView custom section click and section first row click?

UITableView returns the same callback "didSelectRowAtIndexPath" with the same NSIndexPath (0,0) both for section click and section first row click. I'm using custom view for section header view and I need to perform some action on these section rows. Tried checking cell class with [tableView cellForRowAtIndexPath:indexPath] but it's obviously returning the same row cell instead of section cell. Any suggestions?
UPDATE I could add my custom section view to first row instead of adding it as a section, however in that case, I would need to return different row height in "heightForRowAtIndexPath" and that would be not-performanc-wise decision.
UPDATE I'v designed my section view as a subclass of UITableViewCell, because I prefer to get native UITableView callbacks instead of workaround'ing with tap gestures or buttons.
Centurion, if you want to have section that you open/close easily, I suggest you to use the class APLSectionHeaderView.
You can find more information on APLSectionHeaderView.h and APLSectionHeaderView.m
Hope it will help you.
I've been using it, so if you have some question about it...

Getting data from a custom cell

I am dealing with a problem when I try to get my data from custom cell which has two different textfields.
The custom cell was implemented this way:
http://imageshack.us/photo/my-images/441/screenshot20120726at434.png/
And the table view looks like this:
http://imageshack.us/photo/my-images/849/screenshot20120726at431.png/
What I want to do is that when I press SAVE button from the right top corner I should get the values from the two textfields and also the switch status. I don't know how to manage the cells in order to do that. Thank you in advance!
You can create three index paths with section 0 and rows 0, 1, and 2. Then ask your table view for cellForRowAtIndexPath:. You know which type of information you want from each -- the same as what you stored in your datasource method -- and can read it from the matching text field or switch.

How to make two tableview cell in one controller class in iphone

I am making two tableview cell in one controller class on vertical style. I have different value both the cell. Left cell have some name value for eg(name :pradeep),and right side cell have some price value so if select on left cell on 3row and right side cell on 2 row so this two cell value I have to pass for open url.
Please help on this how to know which cell index are selected from both the tableview cell and what the value on that selected cell.
If I understand your requirements correctly then you should probably be using a UIPickerView:
http://www.youtube.com/watch?v=wnxS35JDqok
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html
You can add multiple tableview cell. You need to separate or identify them using Identifier. After creating custom cell, you can add tableview cell into Cellforrowatindex path method.Make sure don't forgot to import "custom cell.h" in your implementation file. Thanks.

Resources