简体   繁体   中英

Multiple tableview within one view controller

I was wandering if its possible to have more than one uiTableView in one ViewController.

For example:

tableView1 and tableView2 in one view controller.

Initial start up of view controller, tableView2 should be disabled and not visible.

tableView1 should show the data associated with it.

When user selects a row from tableView1... it should then show the data corresponding to the selected row in tableView2.

tableView1 should still be enabled, and if user selects another row, the contents of tableView2 should also change respectively.

Thanks for any help or guidance given. :)

Of course you can do this. This is 5 minutes in storyboard.

You should choose UIViewController (not UITableViewController !) And create something like this:

在此处输入图片说明

Then you should create object references with a ctrl key.

在此处输入图片说明

You have to remember that you have to set delegate and dataSource in both tableViews to your ViewController:

在此处输入图片说明

And in yout second table view set initialView to hidden.

Then in your code in method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath you should in first line call:

[self.mySecondTableView setHidden:NO]

and do all your stuff later. That's it.

在此处输入图片说明

EDIT: Now i realize that you have set topic to "multiple" tableViews. This solution is messy enough for two TableViews. I suggest you to use container, and then all tableView will have own ViewController.

You can set different tags and outlets for this two TableView.

Then in

-(void)ViewDidLoad

self.yourSecondTableView.hidden = YES;

to hide second tableView

and when delegates methods was called

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

or

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

you can ask for tag like

if (tableView.tag == yourSecondTableViewTag) 
    return something

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM