重新加载当前ViewController的所有子View
我遇到的情况是,我必须重新加载当前视图的所有子视图......我正在从界面生成器添加所有对象(如按钮、图像......等)......
并且我想在以下情况下重置这些子视图:用户单击按钮...
我尝试了 [self.view setNeedsDisplay];
但它不起作用。
有什么简单的方法可以做到这一点...
有什么建议吗?
I have a situation where i have to reload all subViews of my current view....I am adding all objects(like buttons, images ...etc) from interface builder.....
And i want to reset these subviews when user click on a button...
i tried [self.view setNeedsDisplay];
but it doesn't works.
Is there any simple way to do this...
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这对你有帮助。
一种方法是在 UI 方法上创建,为所需控制器设置默认值或所需值。并在按钮事件上调用它。
May be this is helpful to you.
One way is create on UI method that set default or required value for required controllers. And call it on button event.
我不确定你的代码中发生了什么,但我猜
您应该以编程方式添加所有子视图并刷新按钮单击事件,
或者在viewDidAppear方法中编写代码。
I am not sure that what happening in your code but i guess
You should add all subview programatically and refresh on button click event,
or write code in viewDidAppear method.
重新加载它们听起来像是错误的做法。您可以通过将各种属性设置为默认值,以编程方式轻松地将它们重置为默认状态。一旦你这样做了,我可能会以编程方式创建整个视图和子视图,而不使用 IB。我现在以编程方式完成所有工作,并且发现维护代码更容易。
您可以提出一个基于 NIB 的解决方案,将所有受影响的子视图放入父 UIView 中,然后从 NIB 加载该父视图,然后仅替换父 UIView,但我不推荐这样做。无论如何,您都需要能够在 viewDidLoad 中以编程方式设置子视图属性,以防视图控制器需要根据内存警告卸载/重新加载视图。
Reloading them sounds like the wrong thing to do. You can easily reset them to their default state programmatically by setting the various properties to your defaults. Once you do that I would probably just create the whole view and subviews programmatically without using IB. I do everything programmatically now and find it easier to maintain my code.
You could come up with a NIB based solution by putting all affected subviews within a parent UIView and load just that parent view from a NIB and then replace the parent UIView only but I don't recommend it. You need to able to set subview properties programmatically in
viewDidLoad
anyway in case the view controller needs to unload/reload the view based on memory warnings.