search

Home  >  Q&A  >  body text

ios - 如何通过点击UITableViewCell上的按钮来拿到它所在cell的位置

这个是我的一个订单详情页面,我需要点击退款成功那个按钮跳入退款流程页面,但是数据是从我这个页面的一个数组拿的,所以我需要获取到点击的位置,我之前又在网上查过试过
// UITableViewCell cell = (UITableViewCell )[[but superview]superview];

NSIndexPath *indexPath = [self.tabView indexPathForCell:cell];
//
这个方法,可以并不能,希望有大神能帮我解决一下,如果可以的话,希望能解释一下,大神帮帮忙,谢谢
PHP中文网PHP中文网2809 days ago606

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:39:32

    Add a property to your Cell.h, NSIndexPath *indexPath; when assigning a value to the cell (assigning a value to the cell in the cellForRow or cellWillDisplay method), pass the indexPath of the TableView to the cell and let the cell save it. When the button on the cell is clicked, it is passed through the proxy. Then pass it to VC and it’s OK

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:39:32

    Hey. Are you not using MVC?

    Then why does your cell know whether this line of payment is for testing products, nougat, or cocktails?

    The header file of your cell should have a model attribute

    When you click the button, check the model and you will know what this line is

    reply
    0
  • PHPz

    PHPz2017-04-17 17:39:32

    The tag of the button is set to the array subscript, and finally the data is found based on the subscript

    reply
    0
  • Cancelreply