Note that there are some explanatory texts on larger screens.

plurals
  1. POUILabel not visually refreshing
    primarykey
    data
    text
    <h2>The Problem</h2> <p>I have a <code>UILabel</code> buried in a few layers of subviews and I can't seem to change it's text. The code to update the label is in<code>MyCardSubclass</code>'s <code>updateVisualElements</code> method. The really weird thing is that <strong>when I log the description of these labels, the text has been updated, but it is not visible.</strong> Here's what it looks like:</p> <p>Inside my View Controller's <code>viewDidLoad</code> method I initialize a <code>UIScrollView</code> and my card object. I add its <code>cardView</code> as a subview like so:</p> <pre><code>-(void)viewDidLoad { [super viewDidLoad]; MyCardSubclass *myCard = [[MyCardSubclass alloc]initWithInfo:info andPoint:CGPointMake(5, runningYValue)]; [myCard setParentViewController:self]; [scrollView addSubview:[myCard cardView]]; //Resize scrollView contentSize } </code></pre> <h3>My Card</h3> <pre><code>//header @property (nonatomic, strong) UIView *contentView; @property (nonatomic, strong) UIView *cardView; @property (nonatomic, strong) CardInfo *cardInfo; @property (nonatomic, strong) UIViewController *parentViewController; //implementaion -(UIView *)cardView { CGRect screenRect = [[UIScreen mainScreen] bounds]; UIView *toReturn = [[UIView alloc]initWithFrame:CGRectMake(self.point.x,self.point.y, screenRect.size.width-borderOffset*2, cardViewHeight)]; UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(borderOffset, 0, toReturn.frame.size.width-borderOffset*2, titleHeight)]; [titleLabel setText:self.title]; [toReturn addSubview:titleLabel]; [self.contentView setFrame:CGRectMake(borderOffset, titleHeight, screenRect.size.width-borderOffset, contentViewHeight)]; if(self.contentView) [toReturn addSubview:self.contentView]; else NSLog(@"no contentView"); //other view stuff return toReturn; } </code></pre> <h3>My Card Subclass</h3> <pre><code>//header @property(nonatomic, strong) UILabel *totalAmountLabel; @property(nonatomic, strong) UILabel *availableAmountLabel; @property(nonatomic, assign) double available; //implementation -(UIView *)cardView { [self setContentView:[self contentViewFromCardInfo:self.cardInfo]]; return [super cardView]; } -(UIView *)contentViewFromCardInfo:(CardInfo *)cardInfo { UIView *toReturn = [[UIView alloc]init]; NSString *amount = @"0"; self.totalAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(labelWidth, runningYValue, labelWidth, labelHeight)]; [self.totalAmountLabel setText:amount]; [toReturn addSubview:self.totalAmountLabel]; runningYValue +=self.totalAmountLabel.frame.size.height+spacer; self.availableAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(labelWidth, runningYValue, labelWidth, labelHeight)]; [self.availableAmountLabel setText:@"0"]; [toReturn addSubview:self.availableAmountLabel]; return toReturn; } -(void)updateVisualElements { NSString *amount = @"10" NSString *availableString = @100" //The log descriptions for these labels are okay. [self.totalAmountLabel setText:amount]; NSLog(@"%@",self.totalAmountLabel.debugDescription); [self.availableAmountLabel setText:availableString]; NSLog(@"%@",self.availableAmountLabel.debugDescription); NSAssert([NSThread isMainThread], @"Not on main thread"); NSAssert(self.totalAmountLabel, @"No label"); } </code></pre> <h2>What I've tried</h2> <ul> <li><p>Calling <code>[self.totalAmountLabel setNeedsDisplay]</code> after setting the text</p></li> <li><p>Calling the method on the main thread using <code>[self.totalAmountLabel performSelector:@selector(setText:) withObject:amount afterDelay:0.0]</code></p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload