5

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?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
wshcdr
  • 935
  • 2
  • 12
  • 27

6 Answers6

3

Try this :

[self addChildViewController:viewControllerB];
[self.view addSubview:viewControllerB.view];
streem
  • 9,044
  • 5
  • 30
  • 41
2

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()
Cesare
  • 9,139
  • 16
  • 78
  • 130
1

You can easily embed any viewcontroller in another. check it out:

iOS Nested View Controllers view inside UIViewController's view?

Community
  • 1
  • 1
1

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

Janos
  • 1,987
  • 3
  • 17
  • 24
0

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.

Fábio Oliveira
  • 2,346
  • 21
  • 30
0

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];
    }
Bishal Ghimire
  • 2,580
  • 22
  • 37