Hacker News new | ask | show | jobs
by LinaLauneBaer 5200 days ago
During the code review (see below) I found that you are actually resizing the table view to accomplish the effect. This is (in my opinion) not the right way to do it. Here is a suggestion:

Instead of adjusting the frame of the Table View simply work with the contentInset property. This is how UITableViewController does its job.

Short Code Review if you don't mind: (I only want to help - not to be a jerk)

Line 35: Please remove your -init override. You are doing nothing there and if you want to have custom initialization use initWithCoder: and initWithFrame: instead of init

Line 61: id (star)appDelegate = [[UIApplication sharedApplication] delegate];

Please remove the "(star)"

Line 64: CGRect windowRect = appDelegate.window.bounds;

You are trying to get the window bounds. Why are you not using: CGRect windowRect = self.window.bounds;

Line 73: viewRectAbsolute = FixOriginRotation(viewRectAbsolute, orientation, windowRect.size.width, windowRect.size.height);

Are you aware of: CGRectGetHeight(…) and CGRectGetWidth(…)? I am not saying you should use these functions instead but you could consider using them. I like them very much:

viewRectAbsolute = FixOriginRotation(viewRectAbsolute, orientation, CGRectGetWidth(windowRect), CGRectGetHeight(windowRect));

Line 79:     int remainder = (viewRectAbsolute.origin.y + viewRectAbsolute.size.height + keyboardFrame.size.height) - windowRect.size.height;

Again: Consider the functions mentioned above. More importantly replace "int" with "NSInteger" - or even better with CGFloat.

Line 80:  if (remainder > 0 && !(remainder > frame.size.height + 50)) {

When using CGFloat you want to make sure to use 0.0 and 50.0.

Line 82:         float duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

Why are you assigning the result of -doubleValue to a float?

2 comments

When using CGFloat you want to make sure to use 0.0 and 50.0.

Actually, on iOS, CGFloat is 32 bits, so you should use '0.0f' and '50.0f'.

On the Mac, in, 64-bit, it's a 64-bit value, so your advice would be correct there.

It is slightly annoying there's no easy way to write a CGFloat literal in a cross-platform way apart from the overly verbose '((CGFloat)50.0)'.

You are - of course - correct. Did too much Mac development lately. :)
Cool thanks! I'll look into those changes. I built this when I was learning iOS on the fly a year or so ago, so I'm sure things aren't all done in the absolute best fashion. I'll learn from your suggestions. Thanks!