reload/refresh subViews - setNeedsDisplay doesnt work

后端 未结 3 1730
一向
一向 2020-12-17 04:11

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

相关标签:
3条回答
  • 2020-12-17 04:37

    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];
    
    0 讨论(0)
  • 2020-12-17 04:39

    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)
    
    0 讨论(0)
  • 2020-12-17 04:56

    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.

    0 讨论(0)
提交回复
热议问题