본문 바로가기
iOS

선택된 셀의 인덱스 불러오기

by 냥이있는삶 2019. 5. 30.
반응형

Swift

func addItem(sender: UIButton)
{
    var touchPoint = sender.convert(CGPoint.zero, to: self.maintable)
    // maintable --> replace your tableview name
    var clickedButtonIndexPath = maintable.indexPathForRow(at: touchPoint)
    NSLog("index path.section ==%ld", Int(clickedButtonIndexPath.section))
    NSLog("index path.row ==%ld", Int(clickedButtonIndexPath.row))

}​

Obj-C

CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];
                                                NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];

 

반응형