如何在文本字段编辑时禁用tableview的自动滚动

时间:2018-03-23 08:13:30

标签: ios objective-c uitableview uitextfield

我有一个UITableview,我将该表视图添加为TPKeyboardAvoidingTableView,我有2个UITextField和两个标签,一个问题和两个文本字段,得分1和得分3,如果我把文本字段上的分数我需要更新tableview单元格中的总标签。现在我输入最后一个问题的分数出现在tableview中,那个时候它会自动滚动到顶部。我需要保持回到当前位置,直到我按下完成按钮。

我的代码是

-(void)textFieldDidChange:(id)sender
{
    CGPoint textFieldPoint = [sender convertPoint:CGPointZero toView:self.tableHSEMonthlyReport];
    NSIndexPath *txtIndPath = [self.tableHSEMonthlyReport indexPathForRowAtPoint:textFieldPoint];
    UITextField * textField = (UITextField*)sender;
    NSInteger txtTag = textField.tag;
    NSString * newString = textField.text;

    if (txtIndPath.section==0)
    {
        dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
            //Background Thread
            [[HSEAppData appData].arrayMonthlyGeneralQustion replaceObjectAtIndex:txtIndPath.row withObject:dic];
            [arrayGeneralQuestions replaceObjectAtIndex:txtIndPath.row withObject:question];
            NSIndexPath* indexPath = [NSIndexPath indexPathForRow:txtIndPath.row inSection:txtIndPath.section];

            dispatch_async(dispatch_get_main_queue(), ^(void){
                //Run UI Updates
                [self.tableHSEMonthlyReport beginUpdates];
                HSEMonthlyPerformanceTableViewCell *cell = [self.tableHSEMonthlyReport cellForRowAtIndexPath:indexPath];
                cell.lblTotal.text =[NSString stringWithFormat:@"Total : %@",strtotal];
                [self.tableHSEMonthlyReport endUpdates];

                self.tableHSEMonthlyReport.scrollEnabled = NO;
                self.tableHSEMonthlyReport.scrollsToTop = NO;

                [textField becomeFirstResponder];
            });
        });
    }
}

0 个答案:

没有答案