【发布时间】:2013-06-22 15:34:32
【问题描述】:
单击 Next 按钮时,我试图在 UItableview 中从一个 Uitextfield 跳转到另一个,它向我抛出 Collection <__nsarraym:> 在枚举时发生突变的错误消息。而上一个按钮工作正常。
当我是 tableview 的倒数第二个单元格并想要移动最后一个单元格时会发生这种情况。 下面是一些代码sn-p:
- (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];
}
}];
}
【问题讨论】:
-
代码格式化?如果你解决它,人们会更倾向于阅读你的问题。
标签: ios objective-c uitextfield