有多个select的UITableview?
我正在UITableviewCell中的多个select,我可以这样做,问题发生时,选定的值被添加到数组中,并将其从数组中删除。 我已经从另一个数组中select了值。我认为,下面的场景我犯了错误:“我已经select了多行,然后我一个接一个地取消了它的崩溃”,以下是崩溃– [__ NSArrayM removeObjectAtIndex:]:index 1 beyond bounds [0..0]'
我可以理解的问题,但无法解决,有无论如何获得选定的数组值?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath]; [selectedValue addObject:[[listAns valueForKey:@"o_id"]objectAtIndex:indexPath.row]]; tableViewCell.accessoryView.hidden = NO; tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath]; [selectedValue removeObjectAtIndex:indexPath.row]; //[selectedValue removeLastObject]; tableViewCell.accessoryView.hidden = YES; tableViewCell.accessoryType = UITableViewCellAccessoryNone; }
试试这个,在你的委托方法中临时引用并检查
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath]; NSString *val =[NSString stringWithFormat:@"%@",[[listAns valueForKey:@"o_id"]objectAtIndex:indexPath.row]]; [selectedValue addObject:val]; tableViewCell.accessoryView.hidden = NO; tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath]; NSString *val =[NSString stringWithFormat:@"%@",[[listAns valueForKey:@"o_id"]objectAtIndex:indexPath.row]]; [selectedValue removeObject:val]; tableViewCell.accessoryView.hidden = YES; tableViewCell.accessoryType = UITableViewCellAccessoryNone; }
错误说[__NSArrayM removeObjectAtIndex:]:索引1超越界限[0..0]' ,您尝试删除范围内的索引。您的数组只包含一个值,但您尝试删除第二个索引。
喜欢
为CellforRowAtIndex中的复选标记值创build一个公共数组
{ NSMutableArray *storeSelectedcell } - (void)viewDidLoad { [super viewDidLoad]; storeSelectedcell = [NSMutableArray array]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // initilize the cell and additional code if ([storeSelectedcell containsObject:indexPath]) cell.accessoryType = UITableViewCellAccessoryCheckmark; else cell.accessoryType = UITableViewCellAccessoryNone; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Remove the selection [tableView deselectRowAtIndexPath:indexPath animated:YES]; // allow multiple selection if ([storeSelectedcell containsObject:indexPath]) [storeSelectedcell removeObject:indexPath]; else [storeSelectedcell addObject:indexPath]; // finally refresh your table [tableView reloadData]; }
- 使用新的“Facebook SDK for iOS”与旧的“Facebook iPhone SDK”进行Facebook身份validation
- 如何在命令行中调用builtin-productPackagingUtility
- 拒绝2000万美元的收购,150万以上的用户,以及我如何以每年99美元的价格打造这一切的故事
- 我如何获得当前的应用程序语言环境?
- iOS:在用户拖拽时拉伸/调整UITableView标头的大小?
- pipe理iPhone 5和其他屏幕高度差异的最佳方法
- 位置访问 – 应用程序不要求用户访问位置的权限 – iOS 11
- 点击手势到UITextView的一部分
- 由于信号故障,命令失败 – Swift 2.2 Xcode 7.3