IQKeyboardManager is very useful. IQKeyboardManager inheritance is simple. IQKeyboardManager is constantly updated.

Hit the pit

Recently, I came to know IQKeyboardManager third-party library by chance. It feels better than TPKeyboardAvoiding, which I am using now. So make a decisive substitution. The whole APP has been tested, and it feels good and fully meets the requirements. Until about 5 hours ago, I started writing a UITextView nested in the UITableViewCell of a UITableView, and when I was debugging it, IT crashed.

  • Began baidu, Google search problems, found that no one had encountered this problem.
  • And there is no description on IQKeyboardManager’s official website, so this problem is unique to me.
  • Delete the design to a third-party library associated with UIScrollview. Problems remain.
  • Delete all third-party libraries. Problems remain.
  • Clear the project and reset the simulator. Problems remain.
  • Create a new empty project, copy the same code, and the problem is gone…

why

I think it’s my code again, so let’s start sorting it out.

Resolve the discovery of methods in the original UIViewExtensions class

- (UIView*) superviewOfClassType: (Class) classType
{
    UIView* view = self.superview;
    
    while(view ! = nil) {if ([view isKindOfClass: classType])
        {
            return view;
        }
        
        view = view.superview;
    }
    
    return nil;
}
Copy the code

IQKeyboardManager library IQUIView+Hierarchy class name, that is, overridden.

-(UIView*)superviewOfClassType:(Class)classType
{
    UIView *superview = self.superview;
    
    while (superview)
    {
        if ([superview isKindOfClass:classType])
        {
            //If it's UIScrollView, then validating for special cases if ([superview isKindOfClass:[UIScrollView class]]) { NSString *classNameString = NSStringFromClass([superview class]); // If it's not UITableViewWrapperView class, this is internal class which is actually manage in UITableview. The speciality of this class is that it's superview is UITableView. // If it's not UITableViewCellScrollView class, this is internal class which is actually manage in UITableviewCell. The speciality of this class is that it's superview is UITableViewCell. //If it's not _UIQueuingScrollView class, actually we validate for _ prefix which usually used by Apple internal classes
                if ([superview.superview isKindOfClass:[UITableView class]] == NO &&
                    [superview.superview isKindOfClass:[UITableViewCell class]] == NO &&
                    [classNameString hasPrefix:@"_"] == NO)
                {
                    returnsuperview; }}else
            {
                return superview;
            }
        }
        
        superview = superview.superview;
    }
    
    return nil;
}
Copy the code

In fact, there is no overwriting problem in the classification method name, just at compile time whose method is first, then whose method will be executed.

After modifying methods in the UIViewExtensions class, the display is fine.

When you look at the keyboard popup UI, you can clearly see that the UITableViewWrapperView is indented up after the keyboard popup to avoid overwriting the part where the keyboard is located.

Hopefully IQKeyboardManager can mimic AFNetworking or SDWebImage and use its own prefix to avoid this problem.

// END