UILabel doesn't clear, draws over previous contents - ios

I have a UILabel whose text I change from time to time. When I change the text, however, it doesn't erase the old text -- it re-draws on top of the old text and accumulates.
The UILabel is inside a UITableViewCell.
Has anyone encountered this problem? How do you fix it?

This happen when u customize UITableViewCell by [cell addSubView:UILabel] method.
So let me explain it in some detail:
We use [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; method to get cell to use.
This method can one of two thing:
Return new object of UITableViewCell.
OR
Return old object of UITableViewCell which is not right now on screen. (To improve performance)
If it is fresh than no problem but if it is not than the controls which we have added by
[view addSubView:view] method are already there and we add it again on same position like stack of same controls.
We can solve it by two way:
code in such a way that add [UIView addSubView:UIView] only if it is fresh cell.
(I suggest this) Use subclass of UITableViewCell also call Custom UITableViewCell.
You will find many tutorial on this let me give u some:
Creating a Custom UITableViewCell
How To Design A Custom UITableViewCell From Scratch
If you are using storyboard than it is very easy:
Creating Table Views with Storyboards
Using Xcode Storyboards to Build Dynamic TableViews with Prototype Table View Cells
All the best...

people! I`ve come over similar problem and was trying to create new question, but I decided to write inside this topic for not to make new one. So here is the my case:
I am trying to develop localised app, in which English words set to label normally by wordLabel.text = #"SomeNewWord"; but in case of Russian - new words are written above old ones. this case does not appear while I have some breakpoints to stop activity of the game. When there are no stopping factors the problem shows up. This happens only on iPhone with Russian language selected as default. on iPad everything goes well. I also tried to wordLabel.text to nil before assigning new word to the ULLabel. No reaction at all. The problem is present on both simulator and iPhone 4s for now.
my UILabel is made from storyboard and has #property (nonatomic, weak) IBOutlet UILabel *wordLabel;
UPDATE
after finding this post useful one at the bottom I`ve solved my problem. The answer was to UNCHECK Opaque in interface builder ...

Related

UIButton backgroundColor doesn't change on first UITableViewCell

I'm currently developing an application in Swift and, when i run my application on an iPhone 6 (which runs iOS 12.4.6), occurs a strange problem.
I have a UITableView with many of UITableViewCell inside it and, these cells, contain a UIButton which backgroundColor needs to be updated by a specific condition. The problem is that, only the first cell, doesn't load correctly the color, on the contrary it's loaded only after the cell is reused by the UITableView.
I've had a similar problem before (on the same device) inside a UIViewController and I barely resolved it by shifting the code used to control the backgroundColor from the viewDidLoad method to the viewWillLayoutSubviews method.
In my opinion it's something related with the storyboard overriding some values, I've already tried to set the condition on awakeFromNib inside the UITableViewCell but nothing changes, and I can't actually figure out what else may be causing this problem.
Problem solved, I've actually tried to put the code inside the DispatchQueue.main.async as suggested and it worked fine without any problems.

UICollectionview with IBOutlet-UIButtons not working

I have a two-days-brain-breaking-question to all of you:
I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:
Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.
Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.
I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...
Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.
you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.
Send and receive messages through NSNotificationCenter in Objective-C?
Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.
At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.
Than all your cells may receive notification and react to it.
This is not an optimal way of receiving callbacks, but maybe the simplest.

Static UITableViewCell blank - Swift, iOS 8

I am trying to implement some static cells in a UITableView using Xcode 6 beta 2 and Swift. I have successfully implemented dynamic cells.
When the user clicks on one of the dynamic cells there is a push segue to a new UITableViewController for a UITableView with static cells.
I have set this all up in Xcode and the segue works but when I drag a UILabel onto one of the static cells it just doesn't show up at run time. A few things that might help narrow down whats going on:
The data source methods are not being implemented in the UITableViewController
If I set the background of one of the static cells to a particular color, that shows up at run time
Any advice much appreciated.
Thanks in advance
I "fixed" the issue creating a new storyboard...
On a clean project it was working, maybe it's a bug?
I believe this is the answer here:
https://stackoverflow.com/a/24708004/3827274
TLDR: it's an Xcode bug with changing the view to 'compact' width which seems to only affect alignment/positioning. Click on your UILabel inside the cell and go to the inspector all the way to the bottom and play with the 'Installed' or note if the default one is disabled.

Incorrect UISwitch appearance in UITableViewCell

I created a sectioned UITableView and added a custom cell that includes a UISwitch. All this is done using the storyboard. However, when running the App (Simulator/device), the UISwitch does not look as expected (c.f. attached screenshot).
Any ideas on why this happened are highly appreciated (XCode 4.5.2, iOS 6.0.1). Note: creating a new UIStoryboard does not solve the problem.
I just got the answer to my question: I created a category on UIImageView that sets custom layer properties (e.g. shadowRadius). Setting a breakpoint on the corresponding UIImageView method, it revealed that the UISwitch called it.
I did not get to this point earlier, as I only had a single UIImageView before (and this one was supposed to have custom properties). Thanks for all your comments!

Custom UITableViewCell class in Xcode 4.2

I've been following this Apple Doc to add a custom UITableViewCell that I layed out in an .xib to my project. One problem with the doc is that it seems like it was written for an older version of Xcode.
I'm able to load my UITableViewController that the custom cells are on, but the cells are all blank. My custom cell contains several UILabels, and has a non-default background color. The table that appears when I run has the default white background and no labels. If I change the UITableView's View -> Background on my storyboard, the color of the cells' background changes, but the labels still don't appear.
Of interest is the fact that the data is still in my table's cells. The UITableViewController is itself called as a popover from another controller. When I select one of the cells, the strings from the various label.texts are supposed to be loaded into their own labels on the popover's delegate, and that code works fine (except when I try to include a UINavigationBar in my popover, but that's probably another issue entirely).
I'm still pretty new to iOS developement, so if there's anything I'm leaving out or being unclear about let me know.
Edit - cleaned up code, now is completely different question than when I originally posted, but is still on the same topic. Should I have deleted the old question and posted this as a new question all together, or is it alright that I just edited it?
I'm still not entirely sure what was wrong with what I was doing before, but I managed to get what I wanted. I originally dropped a UITableViewController onto my storyboard set up a popover segue (also on the storyboard) and tried to display the popover with performSegueWithIdentifier. Instead, I now create the popover completely in my code (which I found a nice tutorial for here on SO, by goggling "show popover programmaticly"), without having anything for it on my storyboard. That seems to be the most documented and stable way to show a popover. Once I displayed it that way, my custom cells showed up exactly like I wanted.

Resources