i have trouble with setNeedsDisplay. I have an UIView with a lot of sub UIViews, created in Inteface Builder. I have also an Button with IBAction. In this IBAction i want to
This might help someone, with paging within a container view. The above code gave me the idea to try this and it works.
[self.pageViewController.view removeFromSuperview];
self.pageViewController.view = nil; // unloads the view
[self performSegueWithIdentifier:@"pageViewSegue" sender:self];
Swift 2
This is a replica of Nick Lockwood's answer for some easy copy paste
let parent = self.view.superview
self.view.removeFromSuperview()
self.view = nil
parent?.addSubview(self.view)
Are you trying to reset your view and subviews to their default state in the nib file?
If so the approach above won't work. The only way to do that automatically is to re-load the views from the nib, but you'll need to be clearer about how you are loading the view in the first place before I can help.
If you are loading it into a view controller then the easiest way to refresh it is to remove the view controller from screen and re-create it, but you might be able to reload the view saying something like this (from within the controller):
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
If you are loading the view directly from a nib using [[NSBundle mainBundle] loadNibNamed...] or equivalent, then best way to reload the view is just to throw it away and call that method again.