在我的 uitableview 中,我想在单元格上添加两个按钮,当用户选择某个特定单元格时。现在,如果用户选择另一个单元格,则应从最后一个选定的单元格中删除按钮并添加到新的选定单元格中。
问问题
471 次
3 回答
1
- 在类级别保留对按钮的引用。
- 当你想移动按钮调用
[self.myMovingbutton removeFromSuperview]
然后[cell addSubview:self.myMovingButton]
。
于 2013-01-06T11:30:57.917 回答
0
。H
NSIndexPath *selectedIndexPath;
.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// . . Some Code . . .
if ( selectedIndexPath.row = indexPath.row && selectedIndexPath.section = indexPath.section ) {
button1.hidden = NO;
button2.hidden = NO;
} else {
button1.hidden = YES;
button2.hidden = YES;
}
// . . Some Code . . .
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndexPath = indexPath;
[tableView relaodData];
}
于 2013-01-10T06:47:32.137 回答
0
子类UITableViewCell
并将其添加UIButton
为子类的属性。使用该属性来存储您的按钮实例。重新使用单元格时,您可以检查属性的值,以查看是否需要在添加新按钮之前删除旧按钮。
于 2013-01-06T11:33:39.690 回答