reload/refresh subViews – setNeedsDisplay doesnt work
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 redraw/reload all UIViews (or all UIElements, like UILabel, UIWebView and so on..)
I am doing this, which doesn’t work for me, dont know why.. :
//redraw the UIViews [self.view_card_0 setNeedsDisplay]; [self.view_card_1 setNeedsDisplay]; [self.view_card_stapel setNeedsDisplay]; //other UI Elements [self.webView_0 setNeedsDisplay]; [self.webView_1 setNeedsDisplay]; [self.webView_stapel setNeedsDisplay]; [self.lblCardTitle_0 setNeedsDisplay]; [self.lblCardTitle_1 setNeedsDisplay]; [self.lblCardTitle_stapel setNeedsDisplay]; [self.img_card_0 setNeedsDisplay]; [self.img_card_1 setNeedsDisplay]; [self.img_card_stapel setNeedsDisplay];
What to do for redraw/reload/refresh all UIElements/UIViews and Subviews?
How i load the view:
detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:[NSBundle mainBundle]];
The detailviewcontroller has no viewcontroller, just uiviews, here the hierarchie:
What i expect to do:
*I dont want to reset the UIView, i want to change the background and the content of them. *
I have in my detailview a lot of subviews (uiviews), see above hierarchie. I am displaying content in the UIViews, the content comes from coreData.
The view1 contains the current row of coreData.
The view0 contains the previous row of coreData.
The viewStapel contains the next row of coreData.
With IBAction i want to iterate the coreData rows, display the next row in current if the action is called..and so on..
In Log, the data is changed, but not displayed in the UIViews. Cause of this i need a redraw or reload or something like this, to get displayed the current data.
EDIT 2: SOLVED
I have put the code in a new method and calling this method have solved my problem.
- Relationship between UIVIew and CALayer regarding background image on iOS
- How to remove only user-added subviews from my UIView
- Subviews layer transform and layoutSubviews
- How to create view from a nib file in xcode?
- iOS loadNibNamed confusion, what is best practice?
- View with low alpha - Subview with high alpha
3 Solutions Collect From Internet About “reload/refresh subViews – setNeedsDisplay doesnt work”
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.
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)
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];
- How to use a function from the view controller in the app delegate?
- Can I have a cross-platform framework for OS X and tvOS?
- Apple’s World Wide Developer Relations (WWDR) intermediate certificate is not installed
- iOS builds / ipa creation no longer works from the command line
- Force viewDidLoad to fire on iOS
- How to get the nearest area from a list of locations?
- Xcode: Referencing C++ project from Objective-C project
- The document “MainStoryBoard.storyboard” could not be opened
- How to use the CoreAudio API in Swift
- Setting the frame of an UIView does not work
- Why is -animateWithDuration:delay:options:animations:completion: blocking the UI?
- How to use strncpy in Swift?
- how can I distinguish which part of UITableViewCell has been clicked
- iOS – Build fails with CocoaPods cannot find header files
- How to draw text in PDF context in Swift?