UITableViewCell AccessoryView not displaying as expected

I have a UITableviewCell with a UISwitch in an accessView and it displays correctly at runtime, but as soon as I rotate the device the switch is no longer in the right place. the wrong place for accessoryView

I could use constraints and not use an accessory, but I thought I could use this field. Anyone have an idea?

Thank!

EDIT: here is the config in Interface Builder: enter image description here

EDIT 2: I used a custom cell: enter image description here

with default initialization:

self.textLabel.font = [UIFont preferredDynamicFontForTextStyle:UIFontTextStyleBody fontSize:16.0];
self.backgroundColor = self.contentView.backgroundColor;

self.textLabel.text = item.title;
self.selectedImage = item.imageSelected;
self.unselectedImage = item.image;
self.imageView.image = self.unselectedImage;
// if I do it programmatically
self.accessoryView = [[UISwitch alloc] init];

      

I am not setting limits at all because I am using the default properties.

+3


source to share


4 answers


It seems that if you create a code accessoryView

and editingAccessoryView

the code and install it, everything will be fine!

If you try to install them in UIStoryBoard

, it UITableViewCell

will remove constraints

them after they disappear the first time and will not add them back. It's a shame, but hopefully they change it in a later version.



Hope it helps!

0


source


I just have the same problem as you.

Here are my observations:



  • If you set an accessory by code, it will always be OK whether a cell is selected or not, on both iOS 7 and iOS 8.
  • If you set the AccessoryView to IB, the accessory goes to the top left corner after the first cell selection and only on iOS 8 .

I don't know if the issue is related to IB or the way the accessory is arranged in iOS 8, but so far the workaround is simple: always set the accessory in code to avoid unexpected behavior.

+2


source


I can safely say that your constraints are misconfigured. But without seeing the limitations of the storyboard, there is no way to tell what's broken for sure.

0


source


If you are using autoplay (maybe), you need to set limits first .

0


source







All Articles