UILabel text not being updated
You may be facing an issue with threading as mentioned in the comments above. If you have a method that runs on the main thread and does some activity (such as search a database), updates that you make to the UI will not be committed until the run loop gets control. So, if you have a long, time consuming task going on on the main thread, run this code after setting the text of the label:
- (void)doSomethingTimeConsuming
... consume some time ...
... set text of label ...
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
... continue long operation ...
}
This should flush out any UI changes that you have made. Although this may be a sensible and functional hack, it doesn't beat the alternative. I highly suggest that you perform your app's time consuming tasks on a background thread, and update the UI through the main thread using performSelectorOnMainThread:withObject:waitUntilDone:
. See Apple's page on iOS Thread Management.
UILabel text not updating inside For loop execution Swift
Your issue not occured in my machine. Please restart your machine, maybe problem will resolve.
UILabel Not Updating to match UILabel.text
You need to make sure that the constraint for the UILabel
's width is wide enough to accommodate the text. Otherwise, it is being cutoff and the ...
you are seeing is because the label's line break is set to truncating tail
, which means that the end of the string will be replaced with ...
when the label is too narrow.
So this is an interface builder issue and not a Swift-specific issue. The label's text is being correctly updated, the UI is just not able to properly display it.
If you want the width constraint of the label to change dependent on the text, there are ways to calculate the width of the text and update the constraint's constant to accommodate that text's width.
Why is the label's text not updating?
Your outlets aren't wired up until the view loads.
Try creating a property in your KeysController, say:
var keyText: String?
Set the property after instantiating the view controller:
tipsVC.keyText = firstTips[initialRow]
Then in your KeysController.viewDidLoad
method:
key1.text = keyText
Related Topics
How to Set Image as a Title to Uinavigationbar
Uicollectionview with a Sticky Header
Core Data Does Not React on Changed Predicate
Converting a Vision Vntextobservation to a String
iOS Rich Notification Didreceivenotificationrequest Is Not Fired
Xcode/Simulator: How to Run Older iOS Version
How to Analyze Stack Trace Info of a Thread
How to Animate Add Uisearchbar on Top of Uinavigationbar
How to Intercept Push Notifications for Another App
Differencebetween Embedded Binaries and Linked Frameworks
Why I Couldn't Assign Fetched Values from Firestore to an Array in Swift
How to Manage Sessions with Afnetworking
iPad Multitasking Support Requires These Orientations
Disable the Interactive Dismissal of Presented View Controller
Uitableview:Viewforheaderinsection: Not Called During Reloaddata:
Xcode & Swift - Detecting User Touch of Uiview Inside of Uiscrollview