0

I have a custom UIView containing UILabel as cell.accessoryView = containerView. It was working fine until iOS 14 but as of iOS 15, the containerView is changing its frame on tableView reload. It is displaying properly on the first load but reloading causes the accessoryView to change its frame. My code is

        let notificationLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        
        let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        containerView.clipsToBounds = true
        containerView.backgroundColor = .clear
        containerView.addSubview(notificationLabel!)
        
        cell.accessoryView = containerView

I am changing the frame of the container based on text in UILabel in cellForRowAtIndexPath.

It seems the frame code for containerView is messing up. But this is working fine in iOS 14.

I guess there are some changes and the accessoryView position is allowed to be changed in iOS 15.

Any suggestions to make it work without giving exact x-axis or y-axis in iOS 15?

Hassy
  • 5,068
  • 5
  • 38
  • 63

2 Answers2

0

It's possible what your seeing is the extra "by default" padding added to the section header.

In your Viewdidload add

if (@available(iOS 15.0, *)) {
       [self.tableViewName setSectionHeaderTopPadding:0.0f];
     }
maximus383
  • 584
  • 8
  • 25
0

I could not find a solution for this either. So I gave up on iOS 15's cell.accessoryView.

Instead, my cellForRowAtIndexPath handler calls:

[cell.contentView removeAllSubviews]
[cell.contentView addSubView:myCustomView]
lifjoy
  • 2,158
  • 21
  • 19
  • I am still using cell.accessoryView but I am setting its frame (origin + size) properly, which is working good for iOS 15 and previous. – Hassy Oct 14 '21 at 10:36