iOS tableview的每个cell中放了一个button实现点赞功能,如何解决复用问题

2025-05-10 04:43:42
推荐回答(1个)
回答1:

根据tag值进行获取,在这里设置tag值,

然后在方法

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

中进行获取这个tag值,获取方法是:

UIButton *exitBtn = (UIButton *)[cell viewWithTag:1];//1是我上面设置的tag值

这样就获取到了,你再给他添加action事件就可以了,