How can I call numberOfSectionsInTableView multipl

2019-09-19 01:36发布

问题:

I have implemented 3 UIButtons that represents 3 dates. Depending on which button is selected, I want to display a different UITableView, which represents the selected day schedule of events.

Depending on which button is selected, I hide the other 2 table views.

I have 3 UITableViews, each of which is contained within each UIView, for example, UITableView1 is contained within UIView1 for the selected UIButton1.

How can it be possible to call numberOfSectionsInTableView to return the number of sections depending on which button is selected?

I have something like this:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (date1Selected == YES && date2Selected == NO && date3Selected == NO)
    {
        return [date1 count];
    }
    else if (date1Selected == NO && date2Selected == YES && date3Selected == NO)
    {
        NSLog(@"test");
        return [date2 count];
    }
}

However, it never seems to enter the else if.

How can I achieve this?

回答1:

on click of UIButton1

[UITableView1 reloadData]

on click of UIButton2

[UITableView2 reloadData]

on click of UIButton3

[UITableView3 reloadData]



回答2:

Call [tableView reloadData]. The table will pick up all changes in your data source.



回答3:

reload table view [tableView reloadData]