I have a button in a UITableViewCell which is stored as an ivar called currentButton. When that button is clicked a UIView containing a UIPickerView and UIToolBar is invoked and shown from the bottom of the screen. However, I have looked at other posts for hours and this following code still doesn't work. The cells sometimes scroll down below the keyboard and the cells all the way at the bottom of the UITableView do not scroll up enough to go on top of the UIView backgroundPickerView. This is my code:
CGPoint center = currentButton.center;
CGPoint rootViewPoint = [currentButton.superview convertPoint:center toView:self.view];
NSIndexPath *indexPath = [measurementTableView indexPathForRowAtPoint:rootViewPoint];
CGRect cellRect = [measurementTableView rectForRowAtIndexPath:indexPath];
if (cellRect.origin.y + cellRect.size.height >= backgroundPickerView.frame.origin.y) {
[measurementTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
CGPoint offset = measurementTableView.contentOffset;
offset.y += ((cellRect.origin.y - cellRect.size.height) - backgroundPickerView.frame.origin.y);
[measurementTableView setContentOffset:offset animated:YES];
}
Does anyone see what I am doing wrong here?
UITableViewCell are reused,keeping a reference of a UITableViewCell's subView is not a good approach.
If the special UITableViewCell is not in UITableView's visibleCells
,its frame is undefined.
A solution is:
Create a custom UITableViewCell that has the same structure as you need.
Keep a reference of the indexpath for the custom UITableViewCell.
I hope this will work:
[measurementTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
CGPoint offset = measurementTableView.contentOffset;
offset.y += backgroundPickerView.frame.height;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With