I have an iPad app with a UISplitView. When it is in landscape mode, I have the standard rootViewController (with a uitableview) on the left, with the detail on the right. On the rootViewController's tableview, I have cells, each with a UICustomSwitch. My problem is this:
I select the row (and it remains selected), then I trigger the UICustomSwitch (the UICustomSwitch shows up properly), then select a different row, half of the UICustomSwitch on the previously selected row disappears (either the left or right image). If, however, I select a row, trigger the UICustomSwitch, select the same row once again, then select another row, the UICustomSwitch on the previously selected cell looks fine. I'm unsure how to fix this quirky bug, I have a feeling it has to do with the selection hiding certain properties of UISlider.
I have an iPad app with a UISplitView. When it is in landscape mode, I have the standard rootViewController (with a uitableview) on the left, with the detail on the right. On the rootViewController's tableview, I have cells, each with a UICustomSwitch. My problem is this:
I select the row (and it remains selected), then I trigger the UICustomSwitch (the UICustomSwitch shows up properly), then select a different row, half of the UICustomSwitch on the previously selected row disappears (either the left or right image). If, however, I select a row, trigger the UICustomSwitch, select the same row once again, then select another row, the UICustomSwitch on the previously selected cell looks fine. I'm unsure how to fix this quirky bug, I have a feeling it has to do with the selection hiding certain properties of UISlider.
Any help on this would be much appreciated!
The most likely suspect in any odd misbehavior of table view cells is mistakes in cell reuse in cellForRowAtIndexPath. It's quite easy to not configure recycled cells correctly.
You need to make sure your code for that method only creates the structural elements of a cell when the dequeue method returns nil. Then, the second half of the method should be executed whether you dequeue a recycled cell or create an new cell. In the second half, you should fully configure the cell, setting all fields to explicit values. Your code can't make any assumptions about fields being in their default states, because you may be reconfiguring a recycled cell that has leftover settings from it's last use.
If you go over that logic with a fine-toothed comb and don't find any problems, then the problem must lie somewhere in the logic of your custom control.
You said something about "either the left or right image." Does your custom control use separate images for the left and right side? If so, that's a smoking gun. It's not drawing half the control, so there must be a logic problem with the code that sets up/draws the different parts.
If the whole control is drawn in one step, I'd look to see if there is something covering up part of your control, or it's being clipped somehow.
It's really hard to debug somebody else's code from a source listing. Running the live app in the debugger and stepping through it line by line, adding log statements, etc., is the way to go.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
The most likely suspect in any odd misbehavior of table view cells is mistakes in cell reuse in cellForRowAtIndexPath. It's quite easy to not configure recycled cells correctly.
You need to make sure your code for that method only creates the structural elements of a cell when the dequeue method returns nil. Then, the second half of the method should be executed whether you dequeue a recycled cell or create an new cell. In the second half, you should fully configure the cell, setting all fields to explicit values. Your code can't make any assumptions about fields being in their default states, because you may be reconfiguring a recycled cell that has leftover settings from it's last use.
If you go over that logic with a fine-toothed comb and don't find any problems, then the problem must lie somewhere in the logic of your custom control.
You said something about "either the left or right image." Does your custom control use separate images for the left and right side? If so, that's a smoking gun. It's not drawing half the control, so there must be a logic problem with the code that sets up/draws the different parts.
If the whole control is drawn in one step, I'd look to see if there is something covering up part of your control, or it's being clipped somehow.
It's really hard to debug somebody else's code from a source listing. Running the live app in the debugger and stepping through it line by line, adding log statements, etc., is the way to go.
Thanks for your response! The cellForRowAtIndexPath isn't the problem, i've explicitly defined everything, and the method isn't triggered after the method is called.
I semi-fixed the issue by selecting "Highlighted" and "Selected" under the properties of the UICustomSwitch in Interface Builder. However, now when the actual cell is selected, the switch for some reason hides its image property. Also the same problem occurs as before if I select the same cell twice consecutively (very glitchy). Is there some state or property that is being toggled every time that I need to acknowledge?
I have now deselected "Highlighted" and "selected" (they were causing too many further issues) so now they're back to where they were initially. I'm wondering if theres some other state that is toggled when a cell is selected. That way I could set the minimum and maximum track images for whatever that state is. Any help would be much appreciated!