IOS 7 - How to get the indexPath from button placed in UITableViewCell

get indexpath from button in cell swift
get indexpath of uitableviewcell
uitableviewcell button click swift 4
uitableviewcell button action swift
get indexpath from uicollectionviewcell swift
add button to uitableviewcell programmatically swift
uitableview add row button

I've programmatically created a UITableView and added UISwitch to it's cell accessory view.

This is my code for UISwitch in cell accessory view in cellForRowAtIndexPath method.

UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
[accessorySwitch setOn:NO animated:YES];
[accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = accessorySwitch;

This is the method which is called after the button is clicked.

- (void)changeSwitch:(UISwitch *)sender{

    UITableViewCell *cell = (UITableViewCell *)[sender superview];

    NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
    NSLog(@"%ld",(long)indexPath);

 ……………. My other code…….
}

I am able to print the index path value in iOS 6 But in iOS 7 it prints nil,

Am i missing anything in iOS 7 or there is some other approach to get the indexPath in iOS 7

Thanks, Arun.


NSLog(@"%ld",(long)indexPath); is wrong this will print the pointer address of indexPath

try using following codes

CGPoint center= sender.center; 
  CGPoint rootViewPoint = [sender.superview convertPoint:center toView:self.filterTableView];
  NSIndexPath *indexPath = [self.filterTableView indexPathForRowAtPoint:rootViewPoint];
  NSLog(@"%@",indexPath);

get indexPath of UITableViewCell on click of Button from Cell, Use Delegates: MyCell.swift: import UIKit //1. delegate method protocol MyCellDelegate: AnyObject { func btnCloseTapped(cell: MyCell) } class MyCell:  What I need is when that button in the cell is tapped, to get the indexpath of the cell which has that button. And maybe send it back to the view controller via a delegate or something. Since I'm inside a UITableViewCell subclass, I can't use a solution like this because I don't have a reference to the tableview from inside the cell subclass.


Swift solution: A UITableView extension like this one can be useful for this.

extension UITableView {
    func indexPathForView(view: AnyObject) -> NSIndexPath? {
        let originInTableView = self.convertPoint(CGPointZero, fromView: (view as! UIView))
        return self.indexPathForRowAtPoint(originInTableView)
    }
}

Usage becomes easy everywhere.

let indexPath = tableView.indexPathForView(button)

IOS 7 - How to get the indexPath from button placed in , IOS 7 - How to get the indexPath from button placed in UITableViewCell. Question. I've programmatically created a UITableView and added UISwitch to it's cell  Stack Overflow Public questions the indexPath from button placed in UITableViewCell. 7 or there is some other approach to get the indexPath in iOS 7


If you have button in cell. You can get cell by calling superview. And then can get Indexpath by this way.

 (void)obButtonTap:(UIButton *)sender {

    UITableViewCell *cell = (UITableViewCell *)sender.superview;
    NSIndexPath *indexPath = [tableView indexPathForCell:cell];
}

Programming IOS 7, (In iOS 7, the table cell is itself inside a little horizontal scroll view; the user is actually scrolling the cell to the left, revealing the Delete button behind it.) *)​indexPath { return UITableViewCellEditingStyleNone; } A UITextField is editable if its  However, if your cell has a deep tree of views Mani's answer is best. – Sententia Apr 29 '14 at 7:09 3 Now in iOS 7 it should be UITableViewCell* cell = (UITableViewCell *)[[[sender superview] superview] superview]; Thank you.


You can assign tags to each switch in cellForRowAtIndexPath method like

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
   UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
   [accessorySwitch setOn:NO animated:YES];
   [accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
   cell.accessoryView = accessorySwitch; 
   accessorySwitch.tag = indexPath.row;    
}

- (void)changeSwitch:(UISwitch *)sender{
    NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:[sender tag]];
    NSLog(@"%ld",(long)indexPath);
}

iOS 7 Development Recipes: Problem-Solution Approach, The great thing about this button is that it is programmed not only to call a specific *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) run your app you can tap the “Edit” button to put your UITableView into editing mode,  Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.


SWIFT 4 :

extension UITableView {
    func indexPathForView(view: AnyObject) -> NSIndexPath? {
        let originInTableView = self.convert(CGPoint.zero, from: (view as! UIView))
        return self.indexPathForRow(at: originInTableView)! as NSIndexPath
    }
}

indexpath row after a press button in a table v |Apple Developer , I have a table view with some row, in every row there is a button, a when it is My problem is that I'm not able to get the indexpath row to clean the table after the php update. ahltorp Nov 7, 2016 1:55 AM (in response to angelo.coppi) superview, !(view is UITableViewCell) {; superview = view.superview; }  Returns an index path identifying the row and section at the given point. func index Paths For Rows ( in : CGRect) -> [Index Path]? An array of index paths, each representing a row enclosed by a given rectangle.


Get the indexPath of a cell with delegates/prot |Apple Developer , I have a button in each cell, and when I tap on a cell's button I need to get that cell's And please do not put a link to sort of file sharing services, Please show your func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> OOPer Apr 4, 2019 7:33 PM (in response to jimothy177). Hi Friends, Today am going to post to get current UITableviewCell indexPath by UIButton Action. – (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)index…


4.3. Creating Custom Table View Cell Accessories, iOS 7 Programming Cookbook by Vandad Nahavandipoor tableView cellForRowAtIndexPath: ( NSIndexPath * ) indexPath { UITableViewCell * cell So now we have to somehow link our buttons with the cells to which they belong. to books, videos, and live training; Never lose your place—all your devices are synced  iOS 8 UITableView separator inset 0 not working (20) I have an app where the UITableView's separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.x, however in iOS 8.0 I see that the separator inset is set to the default of 15 on the right.


Elegant Controls In Swift With Closures, Swift 4 Xcode 9 iOS 11 That is how buttons and other Cocoa controls work, for example. for sending messages to an object when a particular event takes place. In some situations you want to have access to the context in which indexPath: NSIndexPath) -> UITableViewCell { if let cell = tableView. I am able to print the index path value in iOS 6 But in iOS 7 it prints nil, Am i missing anything in iOS 7 or there is some other approach to get the indexPath in iOS 7 Thanks, Arun.