establecer la propiedad oculta no tiene efecto inmediato

So I am using subview which contains a label, activity indicator and uiimageview. I have it in a subview and i hide it by default when loading I pop up the subview. However, the subview doesn't unhide itself until AFTER I complete what i need to complete meaning it shows up for about .01 seconds instead of durring the time I want it to

I've tried doing somehting like this.

  do{
     loadingSubview.hidden=false; 
  }while(loadingSubview.hidden);   

to make Sure the property is set before moving on however it yields the same results is there something I am doing wrong?

preguntado el 08 de noviembre de 11 a las 15:11

4 Respuestas

The root cause of your "problem" is that you prevent event loop from processing its events. Drawing is one of them. Another one is user interaction events, etc. If you really want to UNhide the button immediately, you can do:

loadingSubview.hidden = NO; // why "false"??? :)
[self performSelector:@selector(timeConsumingStuff)
           withObject:nil
           afterDelay:0]; // 0 is good here == "when idle"

You can be sure about your button, but it will not be responsive (as well as others) until time-consuming-stuff is finished.

Another solution is to process run-loop events explicitly. (Look at [NSRunLoop runMode:beforeDate:]. But... unless you move your time-consuming-stuff to another thread, there will be a penalty anyway.

respondido 10 nov., 11:03

Note that for most drawing effects, the drawing does NOT happen in real time. Most of the time, you're telling iOS what to draw, and it draws it on the main event loop after you've fallen out of your method. So you can't step through the debugger watching it hide things in your view.

If you want a delayed reaction to something, use one of the:

[self performSelector:@selector(mydelayedtask) withObject:nil afterDelay:1.0f];

which will give you a 1 second delay.

respondido 08 nov., 11:19

I don't want a delayed reaction thats the problem. It's not loading my subview when I need it to. - Endy

You forgot to immediately exit to the run loop when you need it to display. - hotpaw2

You need to exit your current method(s) back to the run loop for any UI updates to take place.

Move on to do the other stuff after this UI update, later in another NSTimer task or other delayed operation (just a couple dozen milliseconds will do). Don't wait inside a method.

respondido 08 nov., 11:20

Solo llama:

[loadingSubview setNeedsDisplay];

Deberías leer "El ciclo de dibujo de vista" described here: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

respondido 08 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.