0

When I build and debug with a breakpoint set ANYWHERE in the code, the simulator window stays all black and I can't see my label. If I build and debug without setting any breakpoints, I am able to see my label. Can anyone help? I would like to be able watch changes occur to my labels, buttons, etc. as I step through lines in the Xcode debugger. By the way, my program uses code to dynamically create and place my UILabel onto the main view.

Is everyone else able to see thier labels and buttons while debugging with breakpoints? I am new to iOS (4.2) development and Objective-C.

3 Answers3

0

As long as you are halting the execution by using a breakpoint, no UI will be updated. So you can't debug in this way. Though you will be able to see the variables and properties. For example, in the debugger you can check whether the text property of label have changed after you set that, but there is no way that the UI will update until you continue the execution.

taskinoor
  • 43,612
  • 11
  • 111
  • 136
0

You'll need to post your run log to work out why your screen is black when you set a breakpoint. My suspicion is that you're setting a breakpoint before the draw cycle, but your question is a little unclear about that.

As far as your goal of seeing changes to the label as you step through the code, this suggests a misunderstanding of the drawing loop. As your code runs, it will make changes to the label data structures, and likely cause setNeedsDisplay: to be called on the label (this is generally called for you automatically when needed). When the next drawing cycle occurs, views marked for display will be redrawn. This will cause drawRect: to be called, but that still doesn't draw on the screen. It just draws into a buffer. After all the drawRect: calls are done, the buffer will be synced to the screen.

There is no point in this cycle that you can set a breakpoint on a method like label.text = @"newstuff" and expect to see it show up on the screen when you step over it.

Rob Napier
  • 250,948
  • 34
  • 393
  • 528
  • Thanks for the information guys. So if I cannot expect the view window to update visual changes as I single step through the debugger, is there any way I can insert a method call in the code where I can initiate an actual visual update to occur, or force this call to occur when I want? – user651903 Mar 09 '11 at 17:08
  • No. You do not control updates to the screen. All required updates in an event loop are composited together before displaying. It is possible that a change you make will be obviated by some other change. For instance, you might change a label, but then the label might be removed from the screen or an opaque view might be obscuring it. The drawing system is optimized to avoid unnecessary draw/composite steps. Circumventing this would trash drawing performance. – Rob Napier Mar 09 '11 at 18:32
  • BTW, here is a similar question on the subject: http://stackoverflow.com/questions/1503761/what-is-the-most-robust-way-to-force-a-uiview-to-redraw/1503828#1503828 – Rob Napier Mar 09 '11 at 18:33
0

Make sure to hit the little "continue" arrow after hitting the breakpoint (which may happen repeatedly). The Xcode Debug window has a larger continue arrow. Until you hit continue, the simulated OS will never get time in the UI run loop to update it's window.

hotpaw2
  • 68,014
  • 12
  • 81
  • 143