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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:55:33+00:00 2026-06-11T19:55:33+00:00

How can I attach an object to a control/UIView in iOS so that I

  • 0

How can I attach an object to a control/UIView in iOS so that I can clearly know which control I’m dealing with?

The scenario is I have a UITableView that is ‘bound’ to an array of strings. I have a custom control (UISwitch) in the cell that sometimes triggers the removal of the row/cell.

In the call back (set by calling addTarget on my UISwitch) I have no way of knowing which cell triggered the event.

Is there a property on UISwitch that I could use to indicate this. Ideally I could attach the original datasource object. In Microsoft technologies, controls often have a tag property that can hold a reference to anything (object/id). However, the tag property in Cocoa Touch is an NSUInteger which doesn’t really help – because storing the index doesn’t work once you’ve deleted an item from the middle of the array; everything is out of sync.

  • 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-11T19:55:34+00:00Added an answer on June 11, 2026 at 7:55 pm

    You can get the tableview cell by using the view hierarchy.

    So in you switch action

    - (IBAction)flip:(id)sender{
      //switch
      UISwitch *s=(UISwitch *)sender;
      //cell
      UITableViewCell *cell=sender.superview; 
      //index path 
      NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
      //then use the index path to access your array of strings
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can see how to attach an event to an object that has no
Does jquery/javascript have any event model that you can attach to your objects? Basically
Following on from this question I now have code that can attach to a
I known that with subversion you can attach arbitrary properties to each files. In
I read that the new delegate method can attach more than one event to
can anyone help? I have an issue with linq2sql and trying to Attach (update)
I have a DataGridView bound to a DataTable that has 1+16 columns defined as
I have javascript object which consists of complex array of structures with nested structures
If I have the following ListView , how can I attach a SelectedIndexChanged event
According to http://support.microsoft.com/kb/288902/en-us You can attach to a specific instance if you know the

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.