How to use 2 UITableView in a UIViewController?


Plz a guide on how I can use 2 UItableView (or more) in a UIViewController and manage them numberOfRowsInSection, ...... & other methods.
Any ideas for this?

+4
source share
5 answers

Assuming your actual problem is assigning the same object as UITableViewDelegate:

UITableViewDelegete methods pass an instance of UITableView to it. You just need to filter out which tables you should work with. For instance:

- (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>... } } 
+7
source
  // 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
     }
 }
+3
source
 if(tableView1){ if(section==0) return 1; /* 1 row for section 0 in the first table. */ if(section==1) return 2; /* 2 rows for section 1 in the first table. */ } if(tableView2){ if(section==0) return 3; /* 3 row for section 0 in the second table. */ if(section==1) return 2; /* 2 rows for section 1 in the second table. */ } 
0
source

why are you going to use two kinds of tables in the UIviewcontroller ?. Perhaps set a tag on each of the table views you add. You can check these tags in delegate methods and make changes.

0
source

use tag .. for example, use table view1 as tag = 0 and use table view2 as tag

0
source

Source: https://habr.com/ru/post/1333870/


All Articles