Thursday, October 26, 2017

iOS UITableViewWrapperView not present in iOS 11 with Xcode9

Leave a Comment

UITableViewWrapperView is not present in iOS11, When I build my App using Xcode9.

I am setting background view for my UITableView by using insertSubview method of UIView, that code is working fine with all iOS versions when I compiled my code using Xcode8 but when I build same code using Xcode9 then content is invisible(on iOS 11) because background layer coming over cells.

Below is debug results -

  1. Xcode9 and iOS 11 -

    A. Before Adding background

    ▿ 2 elements   - 1 : <UIImageView: 0x7fe7f5f045c0; frame = (3 710.667; 408 2.33333); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x604000223f80>>   - 2 : <UIImageView: 0x7fe7f5f01e30; frame = (408.667 3; 2.33333 385); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled> = NO; layer = <CALayer: 0x604000226720>> 

    B. After Adding background

    ▿ 3 elements   - 0 : <UIView: 0x7fe7f5e09840; frame = (0 0; 414 736); layer = <CALayer: 0x60400003d780>>   - 1 : <UIImageView: 0x7fe7f5f045c0; frame = (3 710.667; 408 2.33333); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x604000223f80>>   - 2 : <UIImageView: 0x7fe7f5f01e30; frame = (408.667 3; 2.33333 385); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled> = NO; layer = <CALayer: 0x604000226720>> 
  2. Xcode8 and iOS 11 - UITableViewWrapperView is present -

    A. Before Adding background

    3 elements   - 0 : <UITableViewWrapperView: 0x7ffdbe81cc00; frame = (0 0; 375 647); gestureRecognizers = <NSArray: 0x608000244a10>; layer => <CALayer: 0x608000028cc0>;contentOffset: {0, 0}; contentSize: {375,> 647}>   - 1 : <UIImageView: 0x7ffdbe406af0; frame = (3 641.5; 369 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO;layer = <CALayer: 0x608000028fe0>>   - 2 : <UIImageView: 0x7ffdbe407320; frame = (369.5 637; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO;> layer = <CALayer: 0x608000029140>> 

    B. After Adding background

    4 elements   - 0 : <UIView: 0x7ffdbe505cc0; frame = (0 0; 375 667); layer = <CALayer: 0x60000002a460>>   - 1 : <UITableViewWrapperView: 0x7ffdbe81cc00; frame = (0 0; 375 647); gestureRecognizers = <NSArray: 0x608000244a10>; layer =<CALayer: 0x608000028cc0>; contentOffset: {0, 0};contentSize: {375,647}>   - 2 : <UIImageView: 0x7ffdbe40b0f0; frame = (3 641.5; 369 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO;layer = <CALayer: 0x608000029e00>>   - 3 : <UIImageView: 0x7ffdbe40b550; frame = (369.5 637; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO;layer = <CALayer: 0x608000029f00>> 

Method to set background -

   private func setTableViewBackground() {          let backgroundView = UIView()         backgroundView.frame = view.frame          let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))          let maskLayer: CAShapeLayer = CAShapeLayer()         maskLayer.frame = backgroundView.bounds         maskLayer.path = maskPath.cgPath         backgroundView.layer.mask = maskLayer         backgroundView.backgroundColor = UIColor.red          myCustomTableView.insertSubview(backgroundView, at: 0)     } 

Build using Xcode8 on iOS11

Xcode8_iOS11

Build using Xcode9 on iOS11

enter image description here

I found this link, which confirms that UITableViewWrapperView is removed from iOS11, but just when we compile code using Xcode9?

4 Answers

Answers 1

That's why I don't like to use undocumented features. Apple guys change them as they want without notifications. My suggestion for your case is to put table view on a red substrate in IB and apply your code.

NB. Don't forget to set clipsToBounds property to true.

The function will be even shorter:

private func setTableViewBackground() {     let backgroundView = self.tableViewSubstrate!     let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))     let maskLayer: CAShapeLayer = CAShapeLayer()     maskLayer.path = maskPath.cgPath     backgroundView.layer.mask = maskLayer } 

You can find sample project here: https://github.com/AlexeyGolovenkov/TableWithRoundCorners

Answers 2

Check your target build settings. You might be building to latest OS and switching from XCode 8 to 9 moved your compile target OS from 10 to 11. This may also be a differentiation between any debug versus release builds. You can change your target in XCode 9 to iOS 10 and it will recompile with the issues fixed, but you risk deprecation problems in the future.

Answers 3

Just try to replace myCustomTableView.insertSubview(backgroundView, at: 0) with

myCustomTableView.backgroundView = backgroundView

It's working fine for me.

Answers 4

bro i think this below line of code may useful to you.

old code :

 private func setTableViewBackground() {      let backgroundView = UIView()     backgroundView.frame = view.frame      let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))      let maskLayer: CAShapeLayer = CAShapeLayer()     maskLayer.frame = backgroundView.bounds     maskLayer.path = maskPath.cgPath     backgroundView.layer.mask = maskLayer     backgroundView.backgroundColor = UIColor.red      myCustomTableView.insertSubview(backgroundView, at: 0) } 

Replace with below code :

 private func setTableViewBackground() {      let backgroundView = UIView()     backgroundView.frame = view.frame      let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))      let maskLayer: CAShapeLayer = CAShapeLayer()     maskLayer.frame = backgroundView.bounds     maskLayer.path = maskPath.cgPath     backgroundView.layer.mask = maskLayer     backgroundView.backgroundColor = UIColor.red      // myCustomTableView.insertSubview(backgroundView, at: 0)      myCustomTableView.backgroundView = backgroundView } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment