How to refresh UIViewController programmatically?

浪尽此生 提交于 2020-03-15 06:03:44

问题


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?


回答1:


you can do it in one of two places:

  1. in your viewcontroller
  2. directly in the view

you need to call the function setNeedsDisplay

  1. if you do it from the viewController then [yourViewOutletVariable/viewParameter setNeedsDisplay];
  2. if you write it in the view itself then [self setNeedsDisplay];

hope this helps




回答2:


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.




回答3:


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.




回答4:


If your point is to refresh "UIViewController", then:

[self viewDidLoad];


来源:https://stackoverflow.com/questions/16225397/how-to-refresh-uiviewcontroller-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!