Why Can't I See My Labels in the iPad Simulator When I Use Breakpoints During Debug?
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 a开发者_运维百科ble 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.
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.
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.
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.
精彩评论