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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:00:25+00:00 2026-06-07T05:00:25+00:00

When I add a UIView subclass object to a UIView – for example a

  • 0

When I add a UIView subclass object to a UIView – for example a UISwitch inside a prototype UITableViewCell and I connect this switch with a ViewController via IBAction, how can I find out in this action which table row is the invoked UISwitch in?

I attached the image just to be clear – when the UISwitch is invoked, I want to know which row the invoked UISwitch is in.

xcode

  • 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-06-07T05:00:26+00:00Added an answer on June 7, 2026 at 5:00 am

    I think the “cleanest” way to do this is to have the switch send its action to the cell itself. You’ll need to subclass UITableViewCell to implement that action, and have it pass itself along to a method on the view controller (probably by giving the cell a delegate the view controller is hooked up to). This is a fair amount of pomp; there are more straight-forward but less proper methods below.

    One way is to specify a tag on the UISwitch when configuring the table view cell in the first place (i.e. in your tableView:cellForRowAtIndexPath: method). Something like switch.tag = indexPath.row; you can then retrieve the row from the switch later by asking it for its tag.

    Another way is to search upwards through the UISwitch’s superviews until you find a UITableViewCell and then find its row. Something like:

    UIView *view = switch.superview;
    while (view && ![view isKindOfClass:[UITableViewCell class]]) {
        view = view.superview;
    }
    // at this point, view is nil or a table view cell; ask the table view for its index path
    if (view) {
        NSIndexPath *path = [tableView indexPathForCell:cell];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I use the following to add a UIView subclass in the subviews collection:
I have a UIView subclass MyTextView that I add to a scrollView , and
I have an object that is a subclass of UIView that can be added
I have a UIView subclass on which the user can add a random CGPath.
I am using UIView subclass to add my detail view in my UIViewController .
I have a UIView subclass, and within this I call this other UIView subclass.
I add a UIView , minimisedInterface , to my view controller as normal [self.view
I want to add a UIView of smaller frame as subview to parental view
I want to add a UIView to another UIView so that child view covers
I am trying to add one UIView with a transition style zoom animation like

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.