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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:53:03+00:00 2026-05-27T12:53:03+00:00

I am trying to build a UITableViewCell that looks like this: Since I can’t

  • 0

I am trying to build a UITableViewCell that looks like this:

Since I can’t post an image yet I’ll try to describe it by saying it’s a label (left) with a UISwitch (middle) and the accessory (right).

Hope ya’ll get the picture…

The idea is that the accessoryView is visible but disabled if the switch is off. When the user turns on the switch then they can tap and navigate right to see the list of options that they can select. Trouble is, when the switch is tapped, the cell gets the tap not the switch.

What I gotta’ do? (to make the switch get the tap first). I’m guessing it’s a firstResponder thing but I’m not finding the magic code that I need.

Once I get past this I can probably figure out the enable/disable of the accessory my self…

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-27T12:53:03+00:00Added an answer on May 27, 2026 at 12:53 pm

    Create UISwitch control and add it to the cell content view.

        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *CellIdentifier = @"Cell";
    
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.accessoryType = (UITableViewCellAccessoryNone;
                UISwitch* aSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
    aSwitch.tag = [indexPath row];
    
                CGRect rect = cell.frame;
                CGRect switchRect = aSwitch.frame;
                switchRect.origin = CGPointMake( (rect.size.width / 2) - (aSwitch.frame.size.width / 2), 
                                                   (rect.size.height / 2) - (aSwitch.frame.size.height / 2));
    
                aSwitch.frame = switchRect;
                [aSwitch addTarget:self action:@selector(switchSwitched) forControlEvents:UIControlEventValueChanged];
                [cell addSubview:aSwitch];
    
    
                [aSwitch release];
            }
    
            return cell;
        }
    
        - (void)switchSwitched:(UISwitch*)sender {
    
            if (sender.on) {
    
        UITableViewCell* aCell = [self.tableView cellForRowAtIndexPath:
                                  [NSIndexPath indexPathForRow:sender.tag inSection:0]];
    
        aCell.accessoryType = (sender.on == YES ) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
            }
        }
    

    You can also implement this differently by Subclassing UITableViewCell and adding UITableViewCell nib file.
    Make the UIViewTableController the file owner of the Cell nib file, add to the UIViewController a IBOutlet for the subclassed cell. Load the custom cell using

            [[NSBundle mainBundle] loadNibNamed:@"Your Custom Cell nib file name" owner:self options:nil];
    

    see Apple programming guide for iOS http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7

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

Sidebar

Related Questions

Trying to build a plugin effect that will some what look better than this
Im trying to build a small frame that displays an image. My problem is
I'm trying to get my head around using QuartzCore to render semi-complex text/gradient/image UITableViewCell
I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
I'm trying to build a nice looking config-screen using UITableView (much like the settings
I'm trying build a regex that will replace any characters not of the format:
Trying to build a dynamic gallery that is loaded via AJAX. I'm trying to
Trying to build my android project with Buildr (Apache), but can't find any info
When trying to build I get this error: $ make CC=i686-w64-mingw32-gcc CC aes.c i686-w64-mingw32-gcc:
im trying to build a framework that uses methods from a 3rd party framework.

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.