What is an index path in Swift
Swift: How do I get the indexpath.row when a button is tapped in a cell?
Use an extension for UITableView to get the cell for any view:
@ Paulw11's response to setting up a custom cell type with a Delegate property that sends messages to table view is a good way to go, but it takes some work to set up.
I think it's a bad idea to search the table view cell's view hierarchy for the cell. It's fragile. If you later include your button in a view for layout purposes, this code will likely be corrupted.
The use of view tags is also problematic. You need to remember to set up the tags when creating the cell. If you use this approach in a view controller that is using view tags for a different purpose, you can have duplicate tag numbers and your code may not work as expected.
I created an extension for UITableView that allows you to get the IndexPath for any view contained in a table view cell. It will return a null if the view passed in actually doesn't fall in a table view cell. Below is the source file of the extension in its entirety. You can simply paste this file into your project and then use the included method to find the index path that contains any view.
To use it, you can simply call the method in the IBAction for a button that is in a cell:
(Note that the function only works if the passed view object is contained in a cell that is currently displayed on the screen. This is useful because a view that is not displayed on the screen is actually not part of a specific one Index path that will likely be reassigned to a different index path when the cell is recycled.)
You can download a working demo project that uses the aforementioned extension from Github: TableViewExtension.git
- Where can I buy liquid latex
- What is the nature of infinity
- Paramore will be on a tour soon
- Why did Hitler like the NSDAP
- Are Shetland horses or ponies
- What happened during the last supper
- What are the characteristics of Laissez Faire
- Who wrote the Elton John Lied Fame
- What is DTI in Mortgage
- What is DDL and give an example
- How dangerous is fourth-hand smoke
- Do you like sarcasm
- Why do people wear fake designer clothes?
- How could I donate my sperm
- Licking dogs with affection
- Is rainwater purer than tap water
- Why is area a vector size
- Is the internal dialogue normal?
- Is sour cream vegan
- How much is 45 3 10
- Hiring TCS civil engineers
- What is the future for television advertising
- How did the smilodon breed
- The US is withdrawing from the world
- Will buy Disney Spider Man from Sony
- Scientific consensus is the same as fact
- How do you combine multiple HMMs
- What does square mean in elections
- Can drinking soda make you drunk
- What does anything can happen means
- Why is Google Calico so secret
- How can I start smoking
- Some people are evil than others
- What is the Leidenfrost Effect