17

I am working on custom UITableViewCell where I want to add UITableView inside UITableViewCell so is there any controller available to do the same

This is the image of what I want to add in my project

enter image description here

This is expandable UITableView where after clicking first row inside table and buttons are expanded.

So if any similar controller is available please suggest me.

Thanks in advance.

Sujay
  • 2,510
  • 2
  • 27
  • 47
Pradumna Patil
  • 2,180
  • 3
  • 17
  • 46
  • 3
    possible duplicate of http://stackoverflow.com/questions/17398058/is-it-possible-to-add-uitableview-within-a-uitableviewcell – iAnurag Jun 26 '15 at 05:59
  • i have similar type question any help i posted https://stackoverflow.com/q/45626816/6028575 – Jaydeep Vyas Aug 11 '17 at 04:10

4 Answers4

4

Apple does not recommend table views to be added as subviews of other scrollable objects. If you want to develop such thing, here are the steps for you:

  1. Make separate section for your 'table view' inside your table view
  2. The first row of the section - your clickable row
  3. When the user touches a row, handle it via - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.
  4. Insert other cells into this section by modifying your datasource array.
  5. Reload section or do an update,

    as

    [self.dataSourceArray insertObject:object atIndex:indexPath.row];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
Doro
  • 2,413
  • 2
  • 14
  • 26
  • How come Apple doesn't recommend to do so if the WiFi list inside Settings of every iOS device is done like that? – Josh Mar 08 '16 at 12:41
  • @Josh, the one of the reasons - it's quite hard to work with autolayout and calculating correct dimensions for nested scrollable objects. there is simple way to make this without nesting. and also - were did you see nested uiscrollview hierarchy inside settings? it's simple tableview sections update (like insert / delete). – Doro Mar 09 '16 at 07:24
  • Hi @Doro, when you go into Settings > Wifi , on your iphone, you can see a first section (with the wifi on/off switch, and the active wifi network), and... a second section, with a list of wifi hotspots that grows or shrinks dynamically. I want to implement exactly the same thing, but with something else instead of wifi networks. I am only moderately fluent with swift/ios, do you know if I am looking at this problem from the right side? – Josh Mar 09 '16 at 09:12
  • @Josh, i know two ways to do this - using tableview section and using tableview headers. Please, check this tutorial http://www.appcoda.com/expandable-table-view/ - i hope, it will help you find right direction :) – Doro Mar 10 '16 at 09:49
4

I'll advise against nesting table views. As a user, it's frustrating when one scrollable entity sits inside another scrollable entity. When you swipe, you're never quite sure how the content will behave. It can take several swipes to get from one end of the parent to the other. It matters how you time your swipes. It just sucks to use.

Try this approach of expanding a table view's sections Expand/collapse section in UITableView in iOS

Good luck!

Community
  • 1
  • 1
Neal Ehardt
  • 10,334
  • 9
  • 41
  • 51
1

-> Take separate section for UITableView you want to add view like as tableView.

-> Take the first row of that section.

-> Override the delegate method of UITableView. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

-> In this method update data of tableview and Reload that section.

 [self.dataSourceArray removeObjectAtIndex:indexPath.section];
    [self.dataSourceArray insertObject:object atIndex:indexPath.section];
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
Mujahed Ansari
  • 419
  • 4
  • 13
0

With headers, you can achieve the same. This answer should help you out,

Expand/collapse section in UITableView in iOS

Community
  • 1
  • 1
Manoj Kumar
  • 318
  • 4
  • 14