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 7010521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:00:06+00:00 2026-05-27T22:00:06+00:00

I am using UICsutomSwitch for my application. When I try to create it, I

  • 0

I am using UICsutomSwitch for my application. When I try to create it, I am getting an exception like,

Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[NSArray objectAtIndex:]: index 2 beyond bounds for empty array’

My code is as follows,

UICustomSwitch.h

 #import <Foundation/Foundation.h>


 @interface UICustomSwitch : UISwitch 
{
}
-(void)setLeftLabelText:(NSString *)labelText;
-(void)setRightLabelText:(NSString *)labelText;
@end

UICustomSwich.m

 #import "UICustomSwitch.h"


 @implementation UICustomSwitch
 -(UIView *)slider
 {
  return [[self subviews ] lastObject];
 }
-(UIView *)textHolder
{
  return [[[self slider] subviews]objectAtIndex:2];
 }
-(UILabel *)leftLabel
 {
   return [[[self textHolder] subviews]objectAtIndex:0];

  }
-(UILabel *)rightLabel
{
  return [[[self textHolder] subviews]objectAtIndex:1];

}
-(void)setLeftLabelText:(NSString *)labelText;
{
   [[self leftLabel] setText:labelText];
 }
-(void)setRightLabelText:(NSString *)labelText
{
   [[self rightLabel]setText:labelText];

}
@end

View Controller:

     UICustomSwitch* switchView=[[[UICustomSwitch alloc]initWithFrame:CGRectMake(200,5,90,30)]autorelease];
    [switchView setLeftLabelText:@"F"];
    [switchView setRightLabelText:@"M"];
    [switchView addTarget:self action:@selector(genderAction:) forControlEvents:UIControlEventValueChanged];
    [elementView addSubview:switchView];

I am getting exception at ” return [[[self slider] subviews]objectAtIndex:2];” call. I don’t know what is the wrong, Can you guys please suggest me on this.

Thanks in advance,
Sekhar.

  • 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-27T22:00:07+00:00Added an answer on May 27, 2026 at 10:00 pm

    I ran across this issue and found the answer here:Custom UISwitch Text

    Basically in iOS 4, there were UILabel’s in the UISwitch’s subviews that represented the “On/Off” labels. In iOS 5, there are no UILabels in the subviews array (hence the array error you’re getting). The above link offers an external class you can download and customize. In my opinion, it seems like Apple is discouraging customization of UISwitch. The functionality you’re after could be accomplished another way (segmented control, simulated checkbox, etc).

    Also, in the given link above, the author proposes that the issue might be with not including armv6. I tried this and it does not fix the problem.

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

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using the RichTextArea in GWT, It looks like I can only change the font
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
Using Github's Issue Tracker, how can one create an issue tied to an organization
Using Android TelephonyManager an application can obtain the state of data activity over the
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.

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.