Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2011, 12:12 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 13
mikez12 is on a distinguished road
Default UISlider Issue

I have a UICustomSwitch // // CFCustomSwitch.m // // Created by Hardy Macia on 10/28/09. // Copyr - Pastebin.com

which subclasses 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!
mikez12 is offline   Reply With Quote
Old 09-12-2011, 12:34 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mikez12 View Post
I have a UICustomSwitch // // CFCustomSwitch.m // // Created by Hardy Macia on 10/28/09. // Copyr - Pastebin.com

which subclasses 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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-12-2011, 03:00 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 13
mikez12 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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 this code

[cell.customSwitch setThumbImage:[UIImage imageNamed:@"switchThumb.png"] forState:UIControlStateHighlighted];
[cell.customSwitch setMinimumTrackImage:[UIImage imageNamed:@"switchBlueBg.png"] forState:UIControlStateHighlighted];
[cell.customSwitch setMaximumTrackImage:[UIImage imageNamed:@"switchOffPlain.png"] forState:UIControlStateHighlighted];
[cell.customSwitch setThumbImage:[UIImage imageNamed:@"switchThumb.png"] forState:UIControlStateSelected];
[cell.customSwitch setMinimumTrackImage:[UIImage imageNamed:@"switchBlueBg.png"] forState:UIControlStateSelected];
[cell.customSwitch setMaximumTrackImage:[UIImage imageNamed:@"switchOffPlain.png"] forState:UIControlStateSelected];

to handle the states. I also have the same done for UIControlStateNormal. Is there more states I need to cover?

Last edited by mikez12; 09-12-2011 at 06:28 PM.
mikez12 is offline   Reply With Quote
Old 09-13-2011, 12:47 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 13
mikez12 is on a distinguished road
Default

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!
mikez12 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 406
10 members and 396 guests
7twenty7, apatsufas, Eclectic, eski, fiftysixty, JackReidy, teebee74, tim0504, UMAD, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0