UITextField subview of UITableViewCell, get indexPath of cell

前端 未结 5 1262
余生分开走
余生分开走 2020-11-30 08:30

I have added a UITextField as a subview of a UITableViewCell. Then I have added a target and selector so that I can know

5条回答
  •  悲&欢浪女
    2020-11-30 08:53

    I would like to share @Ertebolle code in swift -

    extension UITableView
    {
        func indexPathForCellContainingView(view1:UIView?)->NSIndexPath?
        {
            var view = view1;
            while view != nil {
                if (view?.isKindOfClass(UITableViewCell) == true)
                {
                    return self.indexPathForCell(view as! UITableViewCell)!
                }
                else
                {
                    view = view?.superview;
                }
            }
            return nil
        }
    }
    

提交回复
热议问题