0
在ios6中, [UITableView dequeueReusableCellWithIdentifier:forIndexPath:]总是返回一个单元格。 那么,如果我想在我的单元格中添加一些按钮处理程序,并且避免每次重用单元格时添加目标。使用[tableView dequeueReusableCellWithIdentifier:forIndexPath:]将单元格中的按钮添加到按钮中。
现在,我使用的标签记忆在细胞已经被挂钩:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(!cell.tag){
cell.tag = 1;
[cell.playButton addTarget:self action:@selector(playInputClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
任何更好的解决方案(不使用的registerClass或registerNib)。
任何建议表示赞赏,
雨果
抱歉超长时间延迟(仅2y ...)。不知道我怎么错过通知...... thx! –