Shukaku
Shukaku

Reputation: 33

Pushing a View on a Different View with Result from Another View

I am creating a simple program where there is a main view which has a segmented control and a logo and some blank space. When the user clicks a segment of the Segmented Control, a view comes up just below the Segmented Control which has 6 buttons that leads user to different views.

I want that the view that appears right after the user clicks the button should not appear on the view where the buttons are (which it will if I use that "addSubView" option). Instead, I want the view to appear on the whole screen which means I want the resultant view (after clicking the button) to appear on the main view.

Thanks in Advance.

Upvotes: 1

Views: 60

Answers (5)

Jaybit
Jaybit

Reputation: 1864

What your asking is: Is there a way that the subview can tell my mainView to add a new view. This can be done by delegation, singletons or notifications. I would suggest using a simple notification:

// This is your observer listening for the notification named @"LaunchViewOne"
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LaunchViewOne) name:@"LaunchViewOne" object:nil];

// This is supplying the notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"LaunchViewOne" object:nil];

So when your button is pressed use postNotification.

Upvotes: 0

picciano
picciano

Reputation: 22701

Take a look at UINavigationController. When the user click on one of the six buttons, you can use the pushViewController:animated: to navigate to the new view. By default, this will also give you a navigation bar at the top of the screen allow the user to go back. If you don't want that, you can turn that off though.

Upvotes: 1

user1176676
user1176676

Reputation:

You can create property for all the controls that you need to access outside of its own class. Then you can access it as below:

Class c = [[Class alloc] init];
someValue = c.mypropery;

Upvotes: 1

yuji
yuji

Reputation: 16725

You can still use addSubView:, just that you don't want to do [viewWhereYouHaveButtons addSubView:someView], but [yourMainView addSubView:someView].

Upvotes: 0

user679424
user679424

Reputation:

i don't understand your question, but you can use a lot of methods to manage views hierarchy

– addSubview:
– bringSubviewToFront:
– sendSubviewToBack:
– removeFromSuperview
– insertSubview:atIndex:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– exchangeSubviewAtIndex:withSubviewAtIndex:

Upvotes: 0

Related Questions