Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:32+00:00 2026-05-23T15:32:32+00:00

My switch will not reset when I call clearbtn, it just remains in the

  • 0

My switch will not reset when I call clearbtn, it just remains in the same state. Also when I call pushme and check to see if the switch is on or off it always detects its off, what would be causing this? How can I fix this? I created a Window-based application just to play around, I didnt create a UIViewController yet, is that what is causing this issue? Thank You.

My .h file

    UIButton *_pushmebutton;
    UITextField *_nametextfield;
    UILabel *_pushmelabel;
    UIImageView *_bgimage;
    UISwitch *_bgswitch;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIButton *pushmebutton;
@property (nonatomic, retain) IBOutlet UITextField *nametextfield;
@property (nonatomic, retain) IBOutlet UILabel *pushmelabel;
@property (nonatomic, retain) IBOutlet UISwitch *bgswitch;
@property (nonatomic, retain) IBOutlet UIImageView *bgimage;
- (IBAction)textFieldReturn:(id)sender;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)pushme:(id)sender;
- (IBAction)clearbtn:(id)sender;
- (IBAction)changebg:(id)sender;

My .m File

#import "MyFirstAppAppDelegate.h"

@implementation MyFirstAppAppDelegate


@synthesize window=_window;
@synthesize pushmebutton = _pushmebutton;
@synthesize nametextfield = _nametextfield;
@synthesize pushmelabel = _pushmelabel;
@synthesize bgswitch = _bgswitch;
@synthesize bgimage = _bgimage;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)dealloc
{
    [_window release];
    [_pushmebutton release];
    [_pushmelabel release];
    [_nametextfield release];
    [super dealloc];
}


-(IBAction)pushme:(id)sender 
{
    if([_nametextfield.text length] == 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please Enter Your Name" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; [alert release];
    }
    else
    {
    [_nametextfield resignFirstResponder];
        if(_bgimage.hidden == false)
        {
            self.pushmelabel.backgroundColor = [UIColor redColor];
        }
        if(_bgswitch.on)
        {
            NSString *msg = [[NSString alloc] initWithFormat:@"Hello, %@ Thanks for using the App! Switch: On!", _nametextfield.text];
            self.pushmelabel.text = msg;
        }
        else
        {
        NSString *msg = [[NSString alloc] initWithFormat:@"Hello, %@ Thanks for using the App! Switch: Off!", _nametextfield.text];
        self.pushmelabel.text = msg;
        }
    }
}
-(IBAction)clearbtn:(id)sender;
{
    _nametextfield.text = @"";
    _pushmelabel.text = @"";
    _pushmelabel.backgroundColor = [UIColor clearColor];
    [_bgswitch setOn:NO animated:YES];
}
-(IBAction)textFieldReturn:(id)sender
{
    [sender resignFirstResponder];
}
-(IBAction)backgroundTouched:(id)sender
{
    [_nametextfield resignFirstResponder];
}
-(IBAction)changebg:(id)sender
{
    if(_bgimage.hidden == false)
    {
    _bgimage.hidden = true;
        _pushmelabel.backgroundColor = [UIColor clearColor];
    }
    else if(_bgimage.hidden == true)
    {
        _bgimage.hidden = false;
        if([_pushmelabel.text length] > 0)
        {
        _pushmelabel.backgroundColor = [UIColor redColor];
        }
    }
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:32:32+00:00Added an answer on May 23, 2026 at 3:32 pm

    My hunch is telling me that you haven’t connected the outlet to the switch in IB. Check for that connection and make it if necessary. If the connection is already there, NSLog your switch in the pushme method and see if it comes out to nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not just for Google Chrome extension but also for JavaScript I am
I'm working on a website that will switch to a new style on a
Using QStackedWidget to switch between the views, I will be able to traverse between
I'm working on a WordPress that will allow the site administrator to switch between
I'm trying to write two batch files that will allow me to switch the
The following source file will not compile with the MSVC compiler (v15.00.30729.01): /* stest.c
I need to have a switch statement that will switch through a list of
I am using YUI reset and jquery AutoGrow together on the same site. It
I have 4 days off and I will use this time to rewrite our
Is there any way to switch off the 'Wrapped around' functionality of Delphi 2010's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.