Chr*_*zzz 17 iphone uitableview
我想在UITableview中选择多行,就像Apple在原生Alarm应用程序中所做的那样(见图片) 
我怎样才能做到这一点?
到目前为止我看到的所有答案都是旧的(并且说"不能做")或者引用本机Mail应用程序中的多行选择.那个方法不是我想要的,因为你必须首先进入"编辑"模式.我希望能够立即选择行.
希望有人能提供帮助.
基督教
Joh*_*ohn 31
我发现最简单的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
Run Code Online (Sandbox Code Playgroud)
您可以通过调用来查看选择了哪些单元格:
NSArray *selectedCells = [self.tableView indexPathsForSelectedRows];
Run Code Online (Sandbox Code Playgroud)
Ale*_*nte 24
在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
做
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}else{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
您还必须使用映射已检查单元格的数组,并且在cellForRowAtIndexPath中,您必须验证是否应检查accessoryType.
时钟应用程序中的"选定"行是具有UITableViewCellAccessoryCheckmark附件类型的单元格.
实现这一目标的可能步骤是:
cellForRowAtIndexPath:检查行的单元格方法中将单元格的accessoryType属性设置为UITableViewCellAccessoryCheckmarkcellForRowAtIndexPath:对未选中的行集小区的单元格accessoryType属性UITableViewCellAccessoryNone| 归档时间: |
|
| 查看次数: |
23542 次 |
| 最近记录: |