我试图在单击 Next 按钮时从 UItableview 中的一个 Uitextfield 跳转到另一个,它向我抛出 Collection <__NSArrayM: 0x837cb90> 在枚举时发生突变的错误消息。而上一个按钮工作正常。
当我是 tableview 的倒数第二个单元格并想要移动最后一个单元格时,就会发生这种情况。下面是一些代码片段:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"Cell";
NSUInteger row = [indexPath row];
CustomCell *Cell = ( CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil)
{
// a new cell needs to be created
Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] ;
Cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSDictionary* product = [dataArray objectAtIndex:indexPath.row];
Cell.lblProductContName.text=[product objectForKey:@"ProductContentsandName"];
Cell.txtQty.delegate = self;
Cell.txtQty.tag = 100 + row;
Cell.txtQty.text=[txtFieldArray objectAtIndex:indexPath.row];
return Cell;
}
下一个按钮、上一个和完成按钮上的代码。
- (void)onPrev:(id)sender
{
NSArray *visiableCells = [self.myTableView visibleCells];
[visiableCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CustomCell *cell = (CustomCell *)obj;
if (cell.txtQty.tag == selectedCellIndex) {
[cell.txtQty resignFirstResponder];
} else if (cell.txtQty.tag == selectedCellIndex - 1){
[cell.txtQty becomeFirstResponder];
*stop = YES;
}
}];
}
- (void)onNext:(id)sender
{
NSArray *visiableCells = [self.myTableView visibleCells];
[visiableCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CustomCell *cell = (CustomCell *)obj;
if (cell.txtQty.tag == selectedCellIndex) {
[cell.txtQty resignFirstResponder];
} else if (cell.txtQty.tag == selectedCellIndex + 1){
[cell.txtQty becomeFirstResponder];
*stop = YES;
}
}];
}
- (void)onDone:(id)sender
{
NSArray *visiableCells = [self.myTableView visibleCells];
[visiableCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CustomCell *cell = (CustomCell *)obj;
if (cell.txtQty.tag == selectedCellIndex) {
[cell.txtQty resignFirstResponder];
}
}];
}