iOS 7: UITableViewController: Changing/Replacing Delete Button

后端 未结 3 1369
春和景丽
春和景丽 2021-01-03 08:12

Disclaimer: I know it\'s not a best practice to tweak that kind of stuff because it may break as Apple decides to change its internal behaviour.

There are s

3条回答
  •  滥情空心
    2021-01-03 08:59

    The reason you don't see the view inside layoutSubviews or willTransitionToState: is that the delete button view does not exist yet or it is not part of the view hierarchy yet. In order to "see" it you need to postpone a little the code that browses the view hierarchy, and by that allowing the OS to create/add the view in the meantime:

    - (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
    
        if (state & UITableViewCellStateShowingDeleteConfirmationMask)
        {
            [self performSelector:@selector(findDeleteButtonViewThroughViewHierarchy:) withObject:self.subviews afterDelay:0];
        }
    }
    

    Note this is a fragile solution since it is based on internal implementation of Apple that might change any time.

    See here an (almost) complete example:

    Customizing iOS 7 Delete button

提交回复
热议问题