iOS开发-UITableView-4(多选)

1.  要做到这一点,最好的方法是将每个选定行复选标记。 你可以做到这一点通过在选定的UITableViewCell实例设置accessoryType到 要取消选择该行,将其设回 对于这些cell/行被选中(比如说,在点击一个按钮),只需遍历表的单元格中寻找或者,在“没有选择”管理的NSSet或类似的表视图的委托 
2.  杰夫LAMARCHE对如何在这里做这个教程: 我还没有尝试过的代码,但它一直在我的脑海里了一会儿 CodeGo.net,知道这一天会当我需要它。 
3.  使用下面的代码来设置单元格ACCESORY类型:
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];

 if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
  thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
 }else{
 	thisCell.accessoryType = UITableViewCellAccessoryNone;
 }
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//add your own code to set the cell accesory type.
return UITableViewCellAccessoryNone;
}

4.  我向后移植 allowsMultipleSelectionDuringEditing allowsMultipleSelection 从iOS5的较旧的iOS。你可以在它叉 它是在下降,只有你需要做的事情就是变化的UITableView以UDTableView(代码或界面生成器) 
5.  下列财产应该可以正常工作,如果你正在开发的iOS5.0 +应用程序
self.tableView.allowsMultipleSelection = YES;

6.  从HIG: 表views提供反馈选择列表项。具体地说,当一个项目可以被选择,则 包含项目列简要underline,当选择它表明,选择已经收到。 然后,一个动作发生:要么一个新的视图显露或行显示一个复选标记,以指示 该项目已经被选择。该行从未仍然突出显示,表视图不显示 持续的选中状态。 您需要推出自己多个选择的样式,无论是与邮件一样,在你的cell的复选标记辅助。 
7.  如果你试图做类似邮件的多重选择(删除邮件,例如),那么你很可能将不得不自己管理所有的选择。多行选择不说是在iPhone上的标准。邮件解决这个复选标记,以指示哪些行被选中。 
8.  伙计们对于多重选择,你只需要
self.tableView.allowsMultipleSelection = YES;
在viewDidLoad中和
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
 tableViewCell.accessoryView.hidden = NO; 
 // if you don't use custom image tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
 UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
 tableViewCell.accessoryView.hidden = YES;
 // if you don't use custom image tableViewCell.accessoryType = UITableViewCellAccessoryNone;
}

9.  注意:这不会的iOS 4 +的工作。这是一个private的,恒定的。做到这一点。 如果你不打算提交您的应用程序在App Store,你可以通过在你的UITableViewController委托调用多行编辑模式:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
 return 3; // Undocumented constant
}

10.  蓝色突出显示的行作为一个列是否被选择实际上是按照HIG页121气馁的指标。复选标记会做的伎俩。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 int selectedRow = indexPath.row;
 cout << "selected Row: " << selectedRow << endl;
 UITableViewCell *indexPathForCell = [tableView cellForRowAtIndexPath:indexPath];
 if (indexPathForCell.accessoryType == UITableViewCellAccessoryNone) {
  indexPathForCell.accessoryType = UITableViewCellAccessoryCheckmark;
 } else {
  indexPathForCell.accessoryType = UITableViewCellAccessoryNone;
 }
}
然后添加您的排列或怎么过您想保存这些被选择的数据。 
11.  我正在寻找的问题,BHAVIN Chitroda的答案sovled它但除了保持复选标记,因为它是在滚动。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  if ( [array indexOfObject:indexPath] == NSNotFound ) {
   [array addObject:indexPath];
   cell.accessoryType = UITableViewCellAccessoryCheckmark;
  } else {
   [array removeObject:indexPath];
   cell.accessoryType = UITableViewCellAccessoryNone;
  }
}
加法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
// Your code here
.
.
.
 if ( [array indexOfObject:indexPath] == NSNotFound ) {
  cell.accessoryType = UITableViewCellAccessoryNone;
 } else {
  cell.accessoryType = UITableViewCellAccessoryCheckmark;
 }
 return cell;
}

12.  测试用的iOS4.3-6.0
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
 if ([controller.searchResultsTableView respondsToSelector:@selector(allowsMultipleSelectionDuringEditing)]) {
  controller.searchResultsTableView.allowsMultipleSelectionDuringEditing = YES;
 }
 else {
  controller.searchResultsTableView.allowsSelectionDuringEditing = YES;
 }
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
 return UITableViewCellAccessoryCheckmark;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值