开发者

TableView won't scroll properly after the keyboard is dimissed!

My TableView scrolls wonderfully until the keyboard shows up... Then it works while the keyboard is visible. When I hide the keyboard, however, the TableView won't scroll at all.

Can anyone think of possible things that could be wrong? I have attached some of the code it it helps, but I would really, really just appreciate any guidance right now. Thanks!

Here is my relevant code (with a bunch of NSLogs--none of the logged values change): The hide keyboard changes the inset to make everything work (it hides a custom keyboard that I might have showing). That is why I always switch the contentInset back...

- (void)textFieldDidBeginEditing:(UITextField *)textField{
 if(self.pickerView.frame.origin.y < 480){
  [开发者_如何学运维self hideKeyboard];
 }
 NSLog(@"A1: (%f,%f,%f,%f)",self.tableView.contentInset.top,self.tableView.contentInset.bottom,self.tableView.contentInset.left,self.tableView.contentInset.right);
 NSLog(@"B1: (%f,%f,%f,%f)",self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.frame.size.height);
 NSLog(@"C1: (%f,%f)",self.tableView.contentSize.height,self.tableView.contentSize.width);
 NSLog(@"D1: (%f,%f,%f,%f)",self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height);
 NSLog(@"E1: (%f,%f)",self.tableView.contentOffset.x,self.tableView.contentOffset.y);
 self.tableView.contentInset = UIEdgeInsetsZero;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
 self.tableView.contentInset = UIEdgeInsetsZero;
 NSLog(@"A1: (%f,%f,%f,%f)",self.tableView.contentInset.top,self.tableView.contentInset.bottom,self.tableView.contentInset.left,self.tableView.contentInset.right);
 NSLog(@"B2: (%f,%f,%f,%f)",self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.frame.size.height);
 NSLog(@"C2: (%f,%f)",self.tableView.contentSize.height,self.tableView.contentSize.width);
 NSLog(@"D2: (%f,%f,%f,%f)",self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height);
 NSLog(@"E2: (%f,%f)",self.tableView.contentOffset.x,self.tableView.contentOffset.y);

 self.exercise.exerciseName = textField.text;
 [appDelegate doOperation:1 onExercise:self.exercise];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)text {
 //Make the DONE button work...
    if([text isEqualToString:@"\n"]) {
        self.tableView.contentInset = UIEdgeInsetsZero;
        [textField resignFirstResponder];
  NSLog(@"A3: (%f,%f,%f,%f)",self.tableView.contentInset.top,self.tableView.contentInset.bottom,self.tableView.contentInset.left,self.tableView.contentInset.right);
  NSLog(@"B3: (%f,%f,%f,%f)",self.tableView.frame.origin.x,self.tableView.frame.origin.y,self.tableView.frame.size.width,self.tableView.frame.size.height);
  NSLog(@"C3: (%f,%f)",self.tableView.contentSize.height,self.tableView.contentSize.width);
  NSLog(@"D3: (%f,%f,%f,%f)",self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height);
  NSLog(@"E3: (%f,%f)",self.tableView.contentOffset.x,self.tableView.contentOffset.y);
        return NO;
    }
return YES;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜