views:

30

answers:

2

Hi all,

In my app I have a custom UIView subclass (let's call it MyView) which contains three buttons and two labels. I add this view to a view controller which also has a table view (I add the instance of MyView at the bottom).

Because of the business logic rules, the labels and one button out of three are hidden in the beginning. So I do this in viewDidLoad:

self.myView.label1.hidden = YES;
self.myView.label2.hidden = YES;
self.myView.button1.hidden = YES;

which works fine. So these three are hidden and the remaining two buttons are visible.

Now this view controller is also a delegate for another class. At some point in time an event occurs in this other class which calls a notification method in my view controller.

In this notification method I have now to show the hidden controls. So I obviously tried the following:

self.myView.label1.hidden = NO;
self.myView.label2.hidden = NO;
self.myView.button1.hidden = NO;

but it doesn't work, they don't appear.

Any idea what I'm doing wrong? Do I need to somehow "repaint" self.myView after this so that the controls become visible? What am I missing here?

Many thanks in advance!

Edit

I have added some NSLogs after setting them visible and the logs show something like this:

label1.hidden = 0
label2.hidden = 0
button1.hidden = 0

So as per the logs, they should be visible.

A: 

Have you confirmed that your notification method is getting called? You shouldn't need to specifically refresh the view, but if you are sure that your method is called, then you can also try adding [self.myView setNeedsDisplay]; into your notification method.

GendoIkari
I can confirm that the notification method is called and I am calling setNeedsDisplay after setting them all to visible as well, but nothing.
Stelian Iancu
+2  A: 

Ok, so I solved the problem. I moved the code that sets the visibility of the controls in another method and I call this method like this:

[self performSelectorOnMainThread:@selector(updateControls) withObject:nil waitUntilDone:NO];

So what do you know, the notification method was called in another thread (I didn't know this, the library I am using is actually not mine and there's nothing in the docs about this fact).

Anyway, it's nice that it works now.

Thanks all!

Stelian Iancu