UA-17470720-3

Jump to content


Photo
- - - - -

Bug in SCTableViewModel keyboardWillShow/Hide?


  • Please log in to reply
7 replies to this topic

#1 jpmcmobile

jpmcmobile

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 11 posts
Reputation: 0
Neutral

Posted 01 January 2014 - 05:08 PM

Hi,

I think there is a bug in keyboardWillShow/Hide in SCTableViewModel.

 

Here's the deal. For historical reasons, our view controllers CANNOT extend UITableViewController. Therefore, SCTableViewModel takes care of making room for the keyboard in the keyboardWillShow method.

 

Everything works great in iOS 6.1, but iOS 7.0 we have an issue: After the keyboard is dismissed, the first row in the table disappears under the navigation bar. The issue is very easy to reproduce: Create a view controller that extends UIViewController, add a UITableView then hook up an SCTableViewModel with a single SCTextFieldCell to the UITableView.

 

I believe that the root cause is that keyboardWillHide assumes that the UITableView contentInset is (0, 0, 0, 0). In iOS 7, by default view controllers automatically adjusts the inset of UIScrollView's (see automaticallyAdjustsScrollViewInsets property). That causes the contentInset to NOT be (0, 0, 0, 0). SCTableViewModel keyboardWillHide overrides the contentInset with (0, 0, 0, 0) when the keyboard disappears.

 

A similar issue probably occurs in iOS 6.1 if the app sets contentInset to something other than (0, 0, 0, 0). A possible fix is to have keyboardWillShow save the original contentInset in a ivar and keyboardWillHide restore it.

 

What do you think?

 

Thanks!



#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 02 January 2014 - 01:26 AM

maybe iOS7 (there are so many "features" that make life frustrating).. something like the view controller settings for extend edges under top bars maybe??


Edited by ozie, 02 January 2014 - 03:49 AM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 jpmcmobile

jpmcmobile

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 11 posts
Reputation: 0
Neutral

Posted 02 January 2014 - 08:13 AM

>>>> maybe iOS7 (there are so many "features" that make life frustrating).. something like the view controller settings for extend edges under top bars maybe??

I'm not sure I understand your point.

 

I understand that keyboardWillShow has to modify contentInset to make the keyboard appear correctly, however when the keyboard is dismissed, keyboardWillHide should restore contentInset back to what it was originally set to.

 

Do you agree?

 

Thanks!



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 02 January 2014 - 01:29 PM

got some code to show so we can see where and what your calling

 

since u said it all works fine in ios6 but not ios7, I'm betting its to do with ios7.. there are so many buys in 7 that it took me awhile to fix all the things in my code that just didn't work anymore from 6.. just have to look at the apple developer forums to see 


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 jpmcmobile

jpmcmobile

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 11 posts
Reputation: 0
Neutral

Posted 07 January 2014 - 11:15 AM

>>>> got some code to show so we can see where and what your calling

Sorry, I'm not sure I understand. Would you like me to post some code here so that you can try to reproduce the issue on your end?



#6 jpmcmobile

jpmcmobile

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 11 posts
Reputation: 0
Neutral

Posted 07 January 2014 - 05:42 PM

Here's the sample code:

 

SecondViewController.h

 

 

#import <UIKit/UIKit.h>

#import <SensibleTableView/SensibleTableView.h>

 

@interface SecondViewController : UIViewController

{

    IBOutlet UITableView *_tableView;

    SCTableViewModel *_tableViewModel;

}

 

@property (nonatomic, retain) NSString *aString;

@property (nonatomic, retain) NSString *anotherString;

 

@end

 
SecondViewController.m
 

#import "SecondViewController.h"

 

@implementation SecondViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    [self setAString:@"hi"];

    [self setAnotherString:@"there"];

    

    _tableViewModel = [[SCTableViewModel alloc] initWithTableView:_tableView];

    SCTableViewSection *section = [[[SCTableViewSection alloc] initWithHeaderTitle:nil] autorelease];

    [_tableViewModel addSection:section];

    

    SCLabelCell *aCell = [SCLabelCell cellWithText:@"A cell" boundObject:self labelTextPropertyName:@"aString"];

    [section addCell:aCell];

    SCTextFieldCell *anotherCell = [SCTextFieldCell cellWithText:@"Another cell" placeholder:nil boundObject:self textFieldTextPropertyName:@"anotherString"];

    [[anotherCell textField] setTextAlignment:NSTextAlignmentRight];

    [section addCell:anotherCell];

}

 

@end

 

The xib file contains a plain UITableView that takes up the entire container space. You can turn Auto Layout on or off - it makes no difference.

 

Write code to push this controller onto a navigation controller and run against iOS 7 simulator.  Tap on the second row ("there") then dismiss the keyboard. Now the first row ("hi") is partially hidden behind the navigation bar.

 

A potential fix is as follows:

1. Add a CGRect ivar to SCTableViewModel.

2. Have [SCTableViewModel keyboardWillShow] save the UITableView's contentInset in the ivar prior to overwriting it.

3. Have [SCTableViewModel keyboardWillHide] restore the contentInset from the ivar, rather than setting it to (0, 0, 0, 0).



#7 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 07 January 2014 - 07:06 PM

Hi.. i had a look at the code and i do remember playing around myself with this type of problem

i also found that if there are more rows than the table can display then you do not see the bottom ones after scrolling.. and thats iOS7 not STV

but yes the current version do not take into account when the view it set to show under top bars etc that when the kb is hidden it sets the inset to 0 and not 64

 

i seem to just set all my views to not extend under top bars to avoid any problems

 

should see some better iOS7 support with v4 of STV.. but iOS7 itself is just buggy.. even apple apps have the same bugs visible

 

I also noticed (and this code might have been just for demo, but instead of using UIViewController use SCTableViewController or SCViewController as it has table models etc build in


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#8 jpmcmobile

jpmcmobile

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 11 posts
Reputation: 0
Neutral

Posted 08 January 2014 - 05:46 AM

Thanks for your feedback.

 

Unfortunately, we cannot extend SCTableViewController/SCViewController: All of our controllers need to inherit common functionality from our base view controller class.

 

On the other hand, I believe that  [SCTableViewModel keyboardWillHide] always setting the contentInset to (0, 0, 0, 0) is incorrect. Even pre-iOS 7, one may want to set a non-(0, 0, 0, 0) contentInset for the UITableView. Showing/hiding the keyboard should NOT cause STV to overwrite that contentInset with (0, 0, 0, 0). Do you agree?

 

As I said, fixing this issue is relatively easy: save the contentInset to an ivar in keyboardWillShow then restore it in keyboardWillHide. I will file a bug report.

 

On a different note: When is STV 4 expected to be released?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users