objc-obsessive
objc-obsessive

Reputation: 825

How can I push a new viewController into an existing view within another view controller?

Is it possible to push a new viewController into an existing view within another view controller?

Here is my setup to begin with:

enter image description here

You can see that I have a UITableView. When a cell is tapped, a new view controller is pushed using this code;

DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];  

Unfortunately this looks like this though and sits on top of the bar at the top saying "Will Roberts"

enter image description here

Why is this happening as it's clearly outside of the view I set it to be pushed from...

Upvotes: 0

Views: 4687

Answers (2)

Kuldeep
Kuldeep

Reputation: 2589

//Presenting new view controller with navigation controller will help you.

DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release]; 

//Edited

DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:viewController1];

[self presentModalViewController:nav1 animated:YES];

Upvotes: 0

Moonkid
Moonkid

Reputation: 916

Instead of "presentViewController", use

DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController pushViewController:viewcontroller animated:YES];
[viewcontroller release];

or use modal view controller

[self presentModalViewController:viewcontroller animated:YES]

Upvotes: 2

Related Questions