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

  • SEARCH
  • Home
  • 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 7070495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:34:24+00:00 2026-05-28T05:34:24+00:00

I am using storyboards and have dragged a scrollview window onto a view. In

  • 0

I am using storyboards and have dragged a scrollview window onto a view. In my code I am programmatically creating a switch object that is somehow not being initialized correctly. The switch appears on the view correctly but whenever I click the switch, an exception is thrown saying

“unrecognized selector sent to instance 0x6a786f0′”

I have also attempted to edit the On/Off text to Yes/No and accessing the switch also throws the same exception. Clearly I have missed something in creating my switch and setting the correct delegates or whatever.

My code to create the switch is..

        UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(x, y, 60, 20)];
        [switchControl addTarget:inputsView action:@selector(actionSwitch:) forControlEvents:UIControlEventTouchUpInside];
        [switchControl setBackgroundColor:[UIColor clearColor]];
        //[(UILabel *)[[[[[[switchControl subviews] lastObject] subviews]
        //               objectAtIndex:1] subviews] objectAtIndex:0] setText:@"Yes"];
        //[(UILabel *)[[[[[[switchControl subviews] lastObject] subviews]
        //               objectAtIndex:1] subviews] objectAtIndex:1] setText:@"No"];


        [inputsView addSubview:switchControl];

inputsView is the name of my UIScrollView that I created in my .h file.

I should note, when the exception is called on clicking the switch, in the error the ‘reason’ is reason: ‘-[UIScrollView actionSwitch:]. When the error is called by trying to adjust the text, the ‘reason’ is reason: ‘-[UIImageView setText:]

Any help on what I am missing would be great.

Thanks

  • 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-28T05:34:25+00:00Added an answer on May 28, 2026 at 5:34 am

    The exception is correct, UIScrolView does not have a method actionSwitch:. The target parameter in addTarget: is the object you want to receive the selector: argument.

    If your posted code is in the class that has the actionSwitch: method then you would use self as the target, like so:

    [switchControl addTarget:self action:@selector(actionSwitch:) forControlEvents:UIControlEventTouchUpInside];
    

    And as a side note. For a UISwitch you generally want your method called for UIControlEventValueChanged, that way if the user just touches the switch but doesn’t “switch” it your method won’t be called.

    Edit in response to: “I just tried changing to ‘self’ for the UISwitch and the error still occurs. I haven’t created an actionSwitch method.”

    Yes, your application would still crash because whatever you pass in as the target must implement the selector/method passed in as the selector.

    The view controller is the ideal place to implement this method. A very standard implementation of this event target would look like:

    -(void)actionSwitch:(UISwitch *)theSwitch{
        if (theSwitch.isOn){
            // Switch was switched on respond accordingly 
        }
        else {
            // Switch was switched off respond accordingly 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dynamic animation using storyboards There is a question i have found that relates directly
I'm using storyboards and I have a UITableView. I have a segue setup that
I have an ios5 app developed using storyboards that currently displays a tab bar
I have dragged a UIImageView onto the UIViewController window in storyboard. I used the
I have a storyboard animation that fades a control out of view using the
I have created a new Xcode project using Storyboards (tab view template). I added
Using storyboards you have no easy access to the first view controller in appDelegate
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a project using StoryBoards and UISearchDisplayController used in the context of a
I'm using XCode 4.2 and have built my UI using Storyboards. I need to

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.