Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UITableViewWrapperView not present in iOS 11 with Xcode9

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?

like image 574
Rahul Avatar asked Oct 17 '17 19:10

Rahul


1 Answers

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

like image 90
Alex Avatar answered Oct 01 '22 19:10

Alex