Hi am beginner in IOS in my project in my Parent ViewController
I have added One ContentView.
Here I would like to load two Child ViewControllers
(they are table-list and table-list Detail page) on my Parent ViewController
ContentView
.
According to my code I am able to load table-list ChildViewController
on my parentViewController
ContentView
as like below image.
But when I click on table-list row I want to load Detail ChildViewContoller
on my parentViewController
ContentView
.
How can I do this?
Please help me.
my code:-
ParentViewController:-
#import "ParentViewController.h"
#import "ChildViewController.h"
@interface ViewController ()
@end
@implementation ParentViewController
@synthesize contentView;
- (void)viewDidLoad
{
[super viewDidLoad];
ChildViewController *tableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"];
tableViewController.view.frame = self.contentView.bounds;
[tableViewController willMoveToParentViewController:self];
[self.contentView addSubview:tableViewController.view];
[self addChildViewController:tableViewController];
[tableViewController didMoveToParentViewController:self];
}
@end
ChildViewController:-
#import "ChildViewController.h"
@interface ChildViewController ()
@end
@implementation ChildViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.items = @[@"One",@"Two",@"Three"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = self.items[indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController*VC = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
[self.navigationController pushViewController:VC animated:YES];
}
@end