开发者

How do I change the UIView programmatically?

开发者 https://www.devze.com 2022-12-26 19:23 出处:网络
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

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 swi开发者_开发百科tch 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?


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];

0

精彩评论

暂无评论...
验证码 换一张
取 消