问题
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:
- in your viewcontroller
- directly in the view
you need to call the function setNeedsDisplay
- if you do it from the viewController then
[yourViewOutletVariable/viewParameter setNeedsDisplay];
- 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