简体   繁体   中英

HOW Implement Two Tableview with different delegate and datasource method In One Class?

I Want to Implement Two Tableview In One Class. I Khow objective-C does not support method overloading and also Khow How Use Two TableView With Same Method but what if have different parameter type?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableView dismisWithIndexPath:indexPath];
}

- (void)tableView:(YALContextMenuTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

You cannot use two separate delegate method for two table views in same view controller.Instead of using two different table view delegate methods,you can better to set tag and name for table Views.

First table view name

 if([tableView isEqual:YourFirstTableViewName]) {
    ......//Your coding part
 }
 else if([tableView isEqual:YourSecondTableViewName]) {
    ......//Your coding part
 }
 else {
    ......//Your coding part
 }

Second use the tag for table view

if(tableView.tag == 0)  //Set tag whatever you want for first table view
{
     ......//Your coding part
}
else if(tableView.tag == 1)  //Set tag whatever you want for second table view
{
     ......//Your coding part
}

In the delegate method, test for the type of table view class to determine which table view called the method,

if ([tableView isMemberOfClass:[YALContextMenuTableView class]]) {
   // do stuff for table 1
} else {
   // do stuff for table 2
}

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