Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 2 UITableView in a UIViewController?


Plz guide that how can i use 2 UItableView(or more) in a UIViewController & manage their
numberOfRowsInSection,......& other methods.
Any ideas for that??

like image 480
user440485 Avatar asked Dec 28 '22 03:12

user440485


2 Answers

Assuming that your actual problem lies in assigning the same object as UITableViewDelegate:

UITableViewDelegete methods pass the UITableView instance to it. You just need to filter out which tableview you need to operate on. For example:

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == yourFirstTableView) {
        // <do whatever on first table view>...
    } else if (tableView == yourSecondTableView) {
        // <do whatever on second table view>...
    }
}
like image 101
Altealice Avatar answered Jan 15 '23 17:01

Altealice


// tableView parameter is the tableView for which the delegate method is called
// u can compare this with your table view references
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == myTableView1) {
        // return data for myTableView1
    } else if (tableView == myTableView2) {
        // return data for myTableView2
    }
}
like image 41
taskinoor Avatar answered Jan 15 '23 19:01

taskinoor