Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Title is not visible for UIContextualAction (UITableView swipe to delete - iOS 11)

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?

like image 516
Advaith Avatar asked Dec 03 '22 21:12

Advaith


1 Answers

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.

like image 56
dr_barto Avatar answered Dec 07 '22 23:12

dr_barto