user1870589
user1870589

Reputation: 3

ios7 UITableView Height , changed but return to default

i'm newer. i find a strange problem about UITableview.

when the uitableview be loaded, the height is 400. and then ,in program, i change the uitableview's height

CGRect talkListFrame = _talkList.frame;
talkListFrame.size.height = _talkListOriginalHeight -keyboardSize.height;
[_talkList setFrame:talkListFrame];

it was good, i changed the height of the uitableview(talkList). but ,when i put data to the uitableview, the height of uitableview return to 400. ※i used a custom uitableviewcell, just put a label in the cell.

UILabel *lable = (UILabel*)[cell viewWithTag:6];
lable.text =@"xxxx";

if i do not use a custom uitablecell, it was good,the height not return.

cell.textLabel.text =@"";

why? the custom cell is the problem

Upvotes: 0

Views: 81

Answers (1)

Sergey Grishchev
Sergey Grishchev

Reputation: 12051

When showing the keyboard don't change the frame. Change contentInset.

I do it like this:

- (void)keyboardWillShow:(NSNotification *)notification{

    CGRect keyboardFrame = [[[notification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];

    [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState animations:^{

        UIEdgeInsets tableViewInsets = UIEdgeInsetsMake(0, 0, keyboardFrame.size.height, 0);
        _talkList.scrollIndicatorInsets = tableViewInsets;
        _talkList.contentInset = tableViewInsets;

    }completion:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification{

    [UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState animations:^{

        UIEdgeInsets tableViewInsets = UIEdgeInsetsZero;
        _talkList.scrollIndicatorInsets = tableViewInsets;
        _talkList.contentInset = tableViewInsets;

    }completion:nil];
}

Upvotes: 1

Related Questions