UISwitchControl trouble!

Discussion in 'iOS Development' started by ipodtouchmaster05, May 28, 2008.

  1. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    Ok so I am trying to make a switch using UISwitchControl on a prefs. cell. Now I did that and when I try to use the switch to execute a command it isnt working. Here is the code for 1 of my cells:

    Code:
                 case 1: {
                     _cell6 = [[UIPreferencesTableCell alloc] init];
                     [_cell6 setTitle:@"Enable/Disable Wifi"];
    wifiControl = [ [ UISwitchControl alloc ]
    		      initWithFrame:CGRectMake(200.0f, 8.0f, 110.0f, 40.0f)];		  
         [ wifiControl setValue: 0.0f];
         int value = [wifiControl value];
         if(value == 1.0f)
    {
    system("launchctl stop com.apple.SpringBoard");
    }	  
    
    As you see im trying to get it to restart the SpringBoard when the switch is turned on. (the name is enable/disable wifi because that is what this will doe eventually im just starting with restarting the springboard because it's easy)
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I got this to work man. I subclassed my switch control and set a timer to detect the value after .5 seconds...like so...


    Code:
    @interface KillSwitch : UISwitchControl
    {
    
    }
    - (void)mouseUp:(struct __GSEvent *)event;
    - (void)handleTimer:(NSTimer *)timer;
    
    @end
    
    @end
    Code:
    #import "KillSwitch.h"
    
    @implementation KillSwitch
    
    - (void)mouseUp:(struct __GSEvent *)event
    {
        NSTimer *timer = [ NSTimer scheduledTimerWithTimeInterval: 0.5
        target: self
        selector: @selector(handleTimer:)
        userInfo: nil
        repeats: NO ];
    
    
    	[ super mouseUp: event ];
    }
    
    - (void)handleTimer:(NSTimer *)timer
    {
    	float switchValue = [ self value ];
    	
    	if(switchValue == 1.0f)
    		{
    			system("killall SpringBoard");
    		}
    }
    
    @end
    Hope this helps you!

Share This Page