更改 UIView 上的子视图? [关闭]
我成功显示了另一个NIB的子视图,我在MainView上有2个按钮和1个UIView,当我单击按钮1时将在UIView上显示NIB1,然后我单击按钮2将在UIView上显示NIB2,但是当我再次单击按钮1 UIView时不再显示 NIB1,但仍然显示 NIB 2,这是我的代码:
更新已解决
在 .h 文件上
IBOutlet UIView *bottomView;
在 .m 文件上
-(IBAction) handleButton1{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib1 isViewLoaded]) {
nib1 = [[NIB1 alloc] initWithNibName:@"NIB1" bundle:nil];
}
[bottomView addSubview:nib1.view];
}
-(IBAction) handleButton2{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib2 isViewLoaded]) {
nib2 = [[NIB2 alloc] initWithNibName:@"NIB2" bundle:nil];
}
[bottomView addSubview:nib2.view];
}
我如何使用代码上的另一个 NIB 刷新 UIView?
谢谢,
我已经解决了这个问题,我从此 http://stackoverflow.com/questions/3915729/refreshing-cell-content-after-deleting-cells
删除 MainView 上的所有子视图
使用:
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
我希望这段代码可以帮助任何人:)。
i have success show subview from another NIB, i have 2 button and 1 UIView on MainView, when i klick button 1 will show NIB1 on UIView, and then i klick button 2 will show NIB2 on UIView, but when i klick again button 1 UIView not show NIB1 again, but still NIB 2, this is my Code :
Updated Solved
On .h file
IBOutlet UIView *bottomView;
On .m file
-(IBAction) handleButton1{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib1 isViewLoaded]) {
nib1 = [[NIB1 alloc] initWithNibName:@"NIB1" bundle:nil];
}
[bottomView addSubview:nib1.view];
}
-(IBAction) handleButton2{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib2 isViewLoaded]) {
nib2 = [[NIB2 alloc] initWithNibName:@"NIB2" bundle:nil];
}
[bottomView addSubview:nib2.view];
}
How i can refresh UIView with another NIB on my code ?
Thanks,
I have solve this case, i remove all subview on MainView from this http://stackoverflow.com/questions/3915729/refreshing-cell-content-after-deleting-cells
use :
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
I hope this code help anyone :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须删除第一个视图
[theViewYouDontWantToShow removeFromSuperview]
。或者您可以使用
[bottomView BringSubviewToFront:nib1/2.view]
。这里附加的只是您添加了一个视图(这有效),在第一个视图之上添加了另一个视图(这也有效),但随后您再次添加了第一个视图。视图不会改变,因为它已经存在了。
You have to remove the first view view
[theViewYouDontWantToShow removeFromSuperview]
.Or you can use
[bottomView bringSubviewToFront:nib1/2.view]
.What was appending here is only that you added a view (this works), added the other view on top of the first one (this works too), but then you added the first one again. The view doesn't change since it's already there.