How can I create a custom view of the delete button when I execute commitEditingStyle in a UITableView

I would like to configure the delete button that appears when the "swipe to left" action is performed in a tableview cell. I am currently setting up a subclass of UITableViewCell, but also want to set up the delete button that is displayed.

My goal is to put three buttons when scrolling.

I choose for another implementation where I used UIScrollview in each cell.

http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/

+2
source share
4 answers

This can help you.

- (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
        {
            for (UIView *subview in self.subviews)
            {
                if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
                {
                    UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
                    [deleteBtn setImage:[UIImage imageNamed:@"arrow_left_s11.png"]];
                    [[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
                }
            }
        }
    }

Link to:

UITableView

uitableview

UITableView

+3

iOS 7, UITableViewCellContentView. , subviews ( iOS, iOS 6.1 -)

        for (UIView *subview in self.subviews) {
            for (UIView *subview2 in subview.subviews) {
                if ([NSStringFromClass([subview2 class]) rangeOfString:@"Delete"].location != NSNotFound) {
                    // Do whatever you want here
                }
            }
        }
+4
-(void)willTransitionToState:(UITableViewCellStateMask)state{
    NSLog(@"EventTableCell willTransitionToState");
    [super willTransitionToState:state];
    if((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake( 320,0, 228, 66)];
        [deleteBtn setImage:[UIImage imageNamed:@"BtnDeleteRow.png"]];
        [[self.subviews objectAtIndex:0] addSubview:deleteBtn];
        [self recurseAndReplaceSubViewIfDeleteConfirmationControl:self.subviews];
        [self performSelector:@selector(recurseAndReplaceSubViewIfDeleteConfirmationControl:) withObject:self.subviews afterDelay:0];
    }
}
+1

iOS 7, - (void)willTransitionToState:, , . - (void)didTransitionToState:. , , . , UIButton

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //your own stuff
        //for some reason, editingAccessoryView cannot be nil and must have a non-CGRectZero frame
        self.editingAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return self;
}

- (void)didTransitionToState:(UITableViewCellStateMask)state
{
    [super didTransitionToState:state];
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        UIView *deleteButton = [self deleteButtonSubview:self];
        if (deleteButton) {
            CGRect frame = deleteButton.frame;
            frame.origin.y += defined_padding;
            frame.size.height -= defined_padding;
            deleteButton.frame = frame;
        }
    }
}

- (UIView *)deleteButtonSubview:(UIView *)view
{
    if ([NSStringFromClass([view class]) rangeOfString:@"Delete"].location != NSNotFound) {
        return view;
    }
    for (UIView *subview in view.subviews) {
        UIView *deleteButton = [self deleteButtonSubview:subview];
        if (deleteButton) {
            return deleteButton;
        }
    }
    return nil;
}
0

Source: https://habr.com/ru/post/1656629/


All Articles