- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在使用 iOS 5 新功能在编辑模式下选择多个单元格时遇到问题。应用结构如下:
-> UIViewController
---> UITableView
----> CustomUITableViewCell
UIViewController
是 UITableView
的委托(delegate)和数据源(我使用的是 UIViewController
而不是 UITableViewController
出于需求原因,我无法更改它)。像下面的代码一样将单元格加载到 UITableView
中。
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell = (CustomTableViewCell*)[tv dequeueReusableCellWithIdentifier:kCellTableIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCellXib" owner:self options:nil];
cell = self.customTableViewCellOutlet;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// configure the cell with data
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
单元接口(interface)是从 xib 文件创建的。特别是,我创建了一个新的 xib 文件,其中 super View 由一个 UITableViewCell
元素组成。为了提供自定义,我将该元素的类型设置为 CustomUITableViewCell
,其中 CustomUITableViewCell
扩展 UITableViewCell
。
@interface CustomTableViewCell : UITableViewCell
// do stuff here
@end
代码运行良好。在表中显示自定义单元格。现在,在应用程序执行期间,我将 allowsMultipleSelectionDuringEditing
设置为 YES
并进入 UITableView
的编辑模式。它似乎工作。事实上,每个单元格旁边都会出现一个空圆圈。问题是当我选择一行时,空圆不会改变它的状态。理论上,圆圈必须从空变为红色复选标记,反之亦然。似乎圆圈仍位于单元格的 contentView
上方。
我做了很多实验。我还检查了以下方法。
- (NSArray *)indexPathsForSelectedRows
它会在编辑模式下的选择过程中更新。它显示正确选择的单元格。
我不太清楚的是,当我尝试在没有自定义单元格的情况下工作时,仅使用 UITableViewCell
,圆圈会正确更新其状态。
你有什么建议吗?提前谢谢你。
最佳答案
对于那些感兴趣的人,我找到了一个有效的解决方案来解决前面的问题。The problem is that when selection style is UITableViewCellSelectionStyleNone
red checkmarks in editing mode aren't displayed correctly.解决方案是创建一个自定义 UITableViewCell
并覆盖一些方法。我正在使用 awakeFromNib
因为我的单元格是通过 xib 创建的。为了找到解决方案,我遵循了这两个 stackoverflow 主题:
这里是代码:
- (void)awakeFromNib
{
[super awakeFromNib];
self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row_normal"]] autorelease];
self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row_selected"]] autorelease];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
if(selected && !self.isEditing)
{
return;
}
[super setSelected:selected animated:animated];
}
- (void)setHighlighted: (BOOL)highlighted animated: (BOOL)animated
{
// don't highlight
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
}
希望对您有所帮助。
关于ios - 自定义 UITableViewCell、UITableView 和 allowsMultipleSelectionDuringEditing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9101810/
是否可以使用 UITableView 的 allowsMultipleSelectionDuringEditing 属性并将其仅应用于 UITableView 中多个部分中的一个? 最佳答案 是的!
我试图通过将 allowsMultipleSelectionDuringEditing 设置为 YES 来删除我的 UITableView 中的一些行。这一切都很好;圆圈显示在左侧。 但是,对于某些单
我有一个表格 View 和自定义 TableViewCell,配置为允许在编辑模式下选择多个单元格,当我选择单元格时会显示一个复选标记。 tableView.allowsMultipleSelecti
我在使用 iOS 5 新功能在编辑模式下选择多个单元格时遇到问题。应用结构如下: -> UIViewController ---> UITableView ----> CustomUITableVie
我有一个 UITableView 配置为允许在编辑模式下选择多个单元格。但是,在触摸/选择单元格后,左侧的空白白色圆圈永远不会变为内部带有白色复选标记的红色圆圈。 我已阅读有关 allowsMulti
一图胜千言... 关于更多背景知识,我有一个 UITableView,它利用 iOS 5 的 allowsMultipleSelectionDuringEditing 设置为 YES。这会导致每当单元
在 iOS 5 中,如果我在 UITableView 上将 allowsMultipleSelectionDuringEditing 设置为 YES,则滑动删除不再有效。内置的邮件应用程序支持滑动删除
我是一名优秀的程序员,十分优秀!