I am using UIContextualAction
to implement swipe to delete functionality for UITableViewCell
. I use + (instancetype)contextualActionWithStyle:(UIContextualActionStyle)style title:(nullable NSString *)title handler:(UIContextualActionHandler)handler
method to construct UIContextualAction
and later set an image to it using setImage:
property.
However when I run this code and try to swipe delete, only image is shown in the menu. The title is missing. When I comment out the setImage
property, title is displayed. Why is this so? Am I missing something in the implementation or is this a bug with Apple?
UIContextualAction
supports either text or image. By setting the image with setImage:
, you basically remove the title you set when creating the object. If you want text and image, you'll have to create images with embedded text.
EDIT
My answer was based on my own experience, unfortunately the official docs for that particular class are of no help at all. I also found a hint on the issue here ("By specifying an image, the title in the initializer is not displayed").
In your comment you say that if the height is >91px, both title and image are shown. That matches this radar (there it says that the height should be >=91px), so it might be a bug after all.
Looks like for the moment, the only options are to either create images with embedded text, or increase the cell height to 91px.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With