更改 UIView 上的子视图? [关闭]

发布于 2024-11-08 22:42:52 字数 1159 浏览 0 评论 0原文


我成功显示了另一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间你老了 2024-11-15 22:42:52

您必须删除第一个视图[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文