I have ViewController_1 with Button_1:
@interface ViewController_1 : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
IBOutlet UIView *secondView;
UITableView *myTable;
}
- (IBAction)buttonPressed:(id)sender;
All tableView delegate methods are implemented in ViewController_1.m
In ViewController_1.xib I have 2 views (View of ViewController_1 and secondView):

when I touch Button_1 I add secondView as subview with myTable:
- (IBAction)buttonPressed:(id)sender
{
[self.view addSubview:secondView];
}
How can I implement that the secondView with table and its methods (DataSource) have been implemented in a separate class?
Because if I have, for example, 10 buttons??? Then in ViewController_1 will be a lot of code!!!
I would suggest you to take a
SecondViewControllerand not view. and when you tap on button then navigate it to thatSecondViewController. Like as you are saying there are several buttons which in turn leads to hide unhide several other views. then It would be hard for you to manage. And yes there will be lots and lots of coding and flags.And if at all you like to add view then you can keep the
SecondViewControllerasUIViewController. Do all the table datasource/delegates methods there andwhile adding it to ViewController_1
Try the following code