ios 如何以编程方式刷新 UIViewController?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16225397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh UIViewController programmatically?
提问by Logan Shire
I have a ViewController in which the user selects a card (a custom UIButton) out of a UIScrollView. I have intercepted the touch event selecting the card and identified it, and then removed it from the data source, but it still exists in the UISubView. How do I get rid of it? Refreshing the view should show it removed from the view. How do I do that?
我有一个 ViewController,用户可以在其中从 UIScrollView 中选择一张卡片(自定义 UIButton)。我截取了选择卡片的触摸事件并进行了识别,然后从数据源中删除了它,但它仍然存在于UISubView中。我该如何摆脱它?刷新视图应显示它已从视图中移除。我怎么做?
回答by liv a
you can do it in one of two places:
您可以在以下两个地方之一进行操作:
- in your viewcontroller
- directly in the view
- 在您的视图控制器中
- 直接在视图中
you need to call the function setNeedsDisplay
你需要调用函数 setNeedsDisplay
- if you do it from the viewController then
[yourViewOutletVariable/viewParameter setNeedsDisplay];
- if you write it in the view itself then
[self setNeedsDisplay];
- 如果您从 viewController 中执行此操作,则
[yourViewOutletVariable/viewParameter setNeedsDisplay];
- 如果你把它写在视图本身中,那么
[self setNeedsDisplay];
hope this helps
希望这可以帮助
回答by TrevorL
Once you have a handle on your view:
一旦你掌握了你的观点:
UIView *v = ...;
[v removeFromSuperview];
You could also call the setNeedsDisplay method on your scroll view after calling removeFromSuperview.
您还可以在调用 removeFromSuperview 后在滚动视图上调用 setNeedsDisplay 方法。
回答by leafduo
You can either let view controller observe your models or update your views manually.
您可以让视图控制器观察您的模型或手动更新您的视图。
I'm not very clear about your question, what is still remaining on your view?
我不是很清楚你的问题,你的观点还剩下什么?
For automatically update views when model changes, I suggest ReactiveCocoa.
为了在模型更改时自动更新视图,我建议使用ReactiveCocoa。
回答by Darius Miliauskas
If your point is to refresh "UIViewController", then:
如果您要刷新“UIViewController”,则:
[self viewDidLoad];