Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two UITableView on a View

How can i achieve following functionality.

I have a View, in that i want to add two UITableView as subView of that View..

  1. monthTableView
  2. dayTableView.

both tableView frame size is parent view size.

but only one table will visible at a time. Example:

i need a method so when ever i called that method need to check which table view currently visible through flag variable.

if (visibleTable == monthTableView)
{

    //need to add subview of parent view is dayTableView
    [self addSubview:dayTableView];
}

if (visibleTable == dayTableView)
{

    //need to add subview of parent view is monthTableView.
    [self addSubview:monthTableView];
}

how can i achieve this.. kindly guide me. thanks in advance...

like image 550
nagarajan Avatar asked Feb 07 '26 21:02

nagarajan


1 Answers

In table view delegate methods, you will see a parameter tableView which is nothing but your current tableView. You can use that to distinguish between your tableViews.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == monthTableView)
    {
        //code for monthTableView
    }
    else if(tableView == dayTableView)
    {
        //code for dayTableView
    } 
    //extra coding
}
like image 62
Baby Groot Avatar answered Feb 09 '26 10:02

Baby Groot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!