Subject to some caveats, you could define properties for each of the two contained tables, connect the outlets in your .xib, and message them directly in your button handlers.
For example:
@interface ParentViewController : UIViewController
@property (nonatomic) IBOutlet Table1Class *table1;
@property (nonatomic) IBOutlet Table2Class *table2;
@end
@implementation ParentViewController
...
- (IBAction)table1FilterButton:(UIButton *)sender
{
[self.table1 filterBy:...];
}
- (IBAction)table2FilterButton:(UIButton *)sender
{
[self.table2 filterBySomethingElse:...];
}
@end
Now, the caveats - you probably won't want to do this if you anticipate that the number of contained view controllers is likely to grow significantly, as it will be unwieldy to have table1
, table2
, table3
, ..., tableN
. You'll probably also want to find a way to extract a common interface (in the form of a protocol) from the two contained view controllers, in order to write less divergent code for handling the filtering of each table.
Maybe something like this, instead:
@protocol ContainedTableProtocol
@property (nonatomic) NSPredicate *contentFilterPredicate;
@property (nonatomic) NSComparator sortComparator;
@end
@interface ParentViewController : UIViewController
@property (nonatomic) IBOutlet UITableViewController<ContainedTableProtocol> *table1;
@property (nonatomic) IBOutlet UITableViewController<ContainedTableProtocol> *table2;
@end
@implementation ParentViewController
- (IBAction)filterTable1ButtonAction:(UIButton *)sender
{
[self filterTable:self.table1];
}
- (IBAction)filterTable2ButtonAction:(UIButton *)sender
{
[self filterTable:self.table2];
}
- (void)filterTable:(UITableViewController<ContainedTableProtocol> *)table
{
// Create predicate and comparator as needed...
NSPredicate *predicate = ... ;
NSComparator comparator = ... ;
table.contentFilterPredicate = predicate;
table.sortComparator = comparator;
}
@end
This uses a common interface to apply the filtering operations to each table view controller, and then codes to that interface rather than an API specific to a particular Table1Class
or Table2Class
.