James Leonard
James Leonard

Reputation: 3763

How to replace self (UIView) with another UIView?

View A has a button upon clicking it, we go to view B

Effectively, i'd like to kill B and replace it with A.

I was thinking that the following should work but, it does not

Calling from View B

ViewController *main = [ViewController new];    
[self addSubview:[main view]];

What am i missing please?

Upvotes: 0

Views: 1349

Answers (2)

Brayden
Brayden

Reputation: 1795

This sounds to me like you're looking for a navigation controller. You can easily take away a navigation controllers NavBar and take away the animations if you don't want them - but this would achieve exactly what you're looking for.

Upvotes: 0

RDM
RDM

Reputation: 5066

Personally I think the easiest way to do this would be by having a UIViewController with an IBOutlet to both UIView objects. You can add and design them both in the interface builder and just set one of them (view B) as hidden (it's a property in UIView). Then, you could specify a button action to toggle the visibility of view B.

I must add though that there are constructs for implementing screen flows, such as the NavigationController. In your case, however, you might also consider the use of the presentModalViewController:animated: method.

It all depends really, but in general it's better practice to make a seperate UIViewController for each UIView in your application.

Hope this helps!

Upvotes: 2

Related Questions