I have a UIViewController (called A), but sometimes I need to show a second UIViewController (called B) , cause I dont wanna disturb the UI actions in A( A still need to respond to some touch actions ), so is there any methods to show B in non-modal way?
6 Answers
Try this :
[self addChildViewController:viewControllerB];
[self.view addSubview:viewControllerB.view];

- 9,044
- 5
- 30
- 41
Here's how you can display a view controller in a non-modal way in Swift:
let newController = RegisterController()
self.addChildViewController(newController)
self.view.addSubview(newController.view)
Remove view in a non-modal way:
view.removeFromSuperview()

- 9,139
- 16
- 78
- 130
You can easily embed any viewcontroller in another. check it out:
iOS Nested View Controllers view inside UIViewController's view?

- 1
- 1

- 605
- 4
- 13
You can embed B in A as a child view.
For an exhaustive description see http://subjective-objective-c.blogspot.co.uk/2011/08/writing-high-quality-view-controller.html, for a simple demo, check out this code: https://github.com/toolmanGitHub/stackedViewControllers

- 1,987
- 3
- 17
- 24
I guess you are talking about presenting view controllers modally in iPhone. In iPad, just for the sake of completeness in the example, you have more ways to show a view controller modally that doesn't fill the whole screen.
You can use UIViewController containment for this. All in all it's just adding a view controller as a child of another while adding it's view to the hierarchy. Check this tutorial at obj.io. This is what @Justafinger is suggesting but complete instead as @Justafinger forgot some important calls.

- 2,346
- 21
- 30
You can
addChildViewController
like this -
- (void)loadContentView
{
CGFloat ht = 0; // height you want to change;
HomeAdsTVC_iPhone *vc1 = [[HomeAdsTVC_iPhone alloc] init];
[self addChildViewController:vc1];
CGRect frame = self.view.bounds;
frame.origin.y = ht;
frame.size.height -= ht;
vc1.view.frame = self.view.bounds;
[self.view addSubview:vc1.view];
[vc1 didMoveToParentViewController:self];
}

- 2,580
- 22
- 37