Jimit
Jimit

Reputation: 652

How do I change the UIView programmatically?

I have created View A and View B. My window has View A displayed on the screen. I also have a UIButton on View A. I want to switch from View A to View B when I click on the Button. I am not using any UIViewController. Is it possible to switch the views without using controller? I am calling buttonAction method on TOUCHUPINSIDE

The problem is that it doesn't do anything when I say

[ViewA removeFromSuperView];

What should I do now?

Upvotes: 0

Views: 885

Answers (1)

drawnonward
drawnonward

Reputation: 53689

If viewB is not in the view hierarchy:

[[viewA superview] addSubview:viewB];

If viewB is in the view hierarchy:

[[viewA superview] bringSubviewToFront:viewB];

Once viewB is in the view hierarchy, then remove viewA:

[viewA removeFromSuperview];

Upvotes: 1

Related Questions