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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:46:35+00:00 2026-05-20T18:46:35+00:00

I a newb to IOS programming and I’m having a problem. I’ve got a

  • 0

I a newb to IOS programming and I’m having a problem. I’ve got a table view that I dynamically load with a UISwitch in each cell using the following code in cellForRowAtIndexPath

UISwitch *mySwitch = [[UISwitch alloc]init];
self.myNewSwitch = mySwitch;
[mySwitch release];
[cell setAccessoryView: self.myNewSwitch];
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventValueChanged];

That works fine. When I click on the switch, the code in changeState runs fine.

Here’s where my problem is. When the user presses a cell in the table, I want to see what state the switch is in (On or Off). My problem is that I can not figure out how to determine that in the didSelectRowAtIndexPath code. I can determine the correct cell, but I couldn’t find out how to access the switch that is on that cell when I searched using Google. Here’s my code for didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //If the on/off switch is on, go to the probes page.  if off, do not do anything
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

   //Determine the switch state here.    
    UISwitch *theSwitch;
    theSwitch = ???????  //<- What do I do???

    if (theSwitch.isOn) {
      //define the probes view controller
      Probes *detailViewController = [[Probes alloc] initWithNibName:@"Probes" bundle:nil];
      //pass in the ip address
      detailViewController.lblIPAddr = cell.detailTextLabel.text;

    // Pass the selected object to the new view controller.
      [self.navigationController pushViewController:detailViewController animated:YES];
      [detailViewController release];
    }
    //Deselect this row
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Any help/code will be helpful.

-NCGrimbo

  • 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-20T18:46:36+00:00Added an answer on May 20, 2026 at 6:46 pm
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        //If the on/off switch is on, go to the probes page.  if off, do not do anything
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
       //Determine the switch state here.         
    
        UISwitch *theSwitch = (UISwitch *)cell.accessoryView ;       
    
        if (theSwitch.isOn) {
          //define the probes view controller
          Probes *detailViewController = [[Probes alloc] initWithNibName:@"Probes" bundle:nil];
          //pass in the ip address
          detailViewController.lblIPAddr = cell.detailTextLabel.text;
    
        // Pass the selected object to the new view controller.
          [self.navigationController pushViewController:detailViewController animated:YES];
          [detailViewController release];
        }
        //Deselect this row
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    

    but I don’t know why you are using,

    UISwitch *mySwitch = [[UISwitch alloc]init];
    self.myNewSwitch = mySwitch;
    [mySwitch release];
    [cell setAccessoryView: self.myNewSwitch];
    

    every time you make new UITableViewCell, self.myNewSwitch is same UISwitch (Last UiSwitch).

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

Sidebar

Related Questions

I am a ruby newb and am having a problem with procs created inside
Jquery/programming newb here. I'm trying to dynamically assign a height to a ul to
a bit newb question: in my DB I've got a table with a binary
newb question there. Having MySQL database/tables structure below: CREATE DATABASE `dbTest` CREATE TABLE IF
Bit of a newb but just having a small problem using jquery cycle all
Sorry for the Newb-ness. I want to create a list of view elements in
I am no newb on OO programming, but I am faced with a puzzling
Total newb to .NET programming (and AJAX) but I've been working on this program
I'm a newb iPhone developer writing an app that has several large JPGs and
Please clue this newb in. I've got a menu with it's object type set

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.