今天在写项目时,再次遇到 通过cell中的按钮获取cell中的Label,看了之前的代码和网上的写法,找出一种自认为很简单的方法,做一下分享,不足之处请大家指导。
点击Button 1,将Label 2显示到UITextField 3上:
-(void) searchShowBtn:(UIButton *)sender
{
SearchCell *cell = (SearchCell *)[[sender superview] superview];
_searchField.text = cell.title.text;
// 获取cell的indexPath
// NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
//通过indexPath 找到cell
SearchCell *cell = (SearchCell *)[self.collectionView cellForItemAtIndexPath:_indexPath];
}