简体   繁体   中英

Delete button on a UITableview Cell blocks custom cell images

I have subclassed a tableview cell and added a couple of labels and images to the custom cell.

   [self.contentView addSubview:lblDesc];
   [self.contentView addSubview:imagesToDisplay];

When i edit the tableView and press the "-" sign the delete button appears on top of the image and other contents.

Some other apps squeeze the contents of the cell to accomodate the delete button.

How do i go about doing this??

Do i need to add a key value Observer [cell addObserver: self forKeyPath: @"showingDeleteConfirmation" options: NSKeyValueObservingOptionNew context: NULL];

Autoresizing is simple - think of it like a web page. Web content "flows", it takes up as much space as the browser window gives it. Autoresizing is the same. There are "masks" which tells UIKit how you want your content to adjust to different frame sizes.

So, for example, if you want your view to shrink or grow from the right side (if it were, for example, left-justified content like a table cell), you'd set the mask like this:

cell.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

Autoresizing also works like a bitwise-OR operation, so if you want it to grow from the right (as above) but also grow from the bottom, you'd "OR" the two together.

cell.autoresizingMask = (UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin);

In the case that this does not work for you (eg you want to put too much on the screen, and need to remove certain elements, etc, or you want to animate somehow differently than the default), consider using the pre-existing method calls in UITableViewCell. From the documentation :

- (void)willTransitionToState:(UITableViewCellStateMask)state

This will be called right before the cell changes state (normal->editing or the other), so if you need to do anything special to handle the animation to the editing state, this is your opportunity to do so. The docs state:

Subclasses of UITableViewCell can implement this method to animate additional changes to a cell when it is changing state. UITableViewCell calls this method whenever a cell transitions between states, such as from a normal state (the default) to editing mode. The custom cell can set up and position any new views that appear with the new state. The cell then receives a layoutSubviews message (UIView) in which it can position these new views in their final locations for the new state. Subclasses must always call super when overriding this method.overriding this method.

您需要设置适当的autoresizingMask以便当contentView更改大小时按钮可以正确移动。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM