0

I have got a DetailViewController with a UIView (white background). Inside this UIView I have got a couple of labels which I want to adress dynamically. So I decided to use viewWithTag

enter image description here

Here is my code:

    UILabel *l = (UILabel*)[_bgresult viewWithTag:6];
    l.text = @"TEST";

But the text never appears. What do I wrong?

Raphael
  • 512
  • 1
  • 6
  • 18
  • You should probably investigate using `IBOutlet`s.. – Ian MacDonald Jan 16 '15 at 22:25
  • where are you calling the update to the label's text? if you put in a breakpoint just after calling `viewWithTag:` is your `UILabel` non-nil? – Louis Tur Jan 16 '15 at 22:25
  • 1
    Try `NSLog(@"%@",[_bgresult viewWithTag:6]);` and what is the result you are getting ? – Midhun MP Jan 16 '15 at 22:31
  • @IanMacDonald: Yes but I want to go through the labels in a for loop like this: `for (int i=0; i<[result count]; i++) {UILabel *l = (UILabel*)[_bgresult viewWithTag:6+i]; l.text = [result objectAtIndex:i]; }` – Raphael Jan 17 '15 at 08:26
  • @MidhunMP yes it's (null), but I don't know why? – Raphael Jan 17 '15 at 08:28
  • @Raphael: First check you set the tag for that label, second check whether you connected the outlet for `_bgresult` – Midhun MP Jan 17 '15 at 08:30

1 Answers1

1

I put the code into - (void)viewDidAppear:(BOOL)animated and now it works. Nevertheless thanks for your help!

Raphael
  • 512
  • 1
  • 6
  • 18