IOS 6 和 IOS7 UITableViewCell上添加控件的獲取

假設每一個cell上面都有UIButton,怎麼判斷哪一個Cell上的按鈕被按下了呢?code

IOS6上blog

-(IBAction)btnClick:(id)sender

{

  UIButton *btn = (UIButton *)sender;

  UITableViewCell *cell = [btn superView];

  NSIndexPath *index = [self.tableView indexPathForCell:cell];

  xxxx

}

 IOS7上一樣的方式你會發現btn的superView變成了io

UITableViewCellScrollView

,那麼IOS7怎麼獲取呢?能夠按照這樣的方法table

設置每一個按鈕的Tag

cell = (UITableViewCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:btn.tag inSection:0]];
相關文章
相關標籤/搜索