UITableViewCell 上的按钮点击事件

     

    以前做tableViewCell的button点击事件,总是建立一个全局的可变数组,把data放在数组里,点击获取button的tag值,根据tag从数组了里取data。

       其实,如果section只有一个的时候,可以直接获取点击的路径来点击的cell。

 

   1 NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:tag_value inSection:0];//因为table只有一个section

   2 UITableViewCell * selectCell = (UITableViewCell *)[self.table cellForRowAtIndexPath:selectIndexPath]; 

 

      如果有多个section的时候怎么办呢?

      我想到一个比较笨的方法, section i ,row j :  button的tag =   i*1000  + j ;

 

     1 NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:(tag_value%1000) inSection:(tag_value/1000)];   

   

        如果您想到更好的方法,欢迎留言讨论~

posted on 2015-09-28 10:10  MichaelMao  阅读(903)  评论(0编辑  收藏  举报