我試圖在單擊Next按鈕時從一個Uitextfield跳轉到另一個,它拋出錯誤信息集合< __NSArrayM:0x837cb90>被枚舉時發生了變化。而「上一個」按鈕工作正常。集合<__ NSArrayM:0x837cb90>在枚舉時發生了變化
當我是桌面視圖的倒數第二個單元並想要移動最後一個單元格時,會發生這種情況。 下面是一些代碼片段:
- (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;
}
代碼在Next按鈕,上一頁和完成按鈕。
- (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];
}
}];
}
代碼格式化?如果你修復它,人們會更傾向於閱讀你的問題。 – Abizern