Umair_uas
Umair_uas

Reputation: 673

Change position of delete button in UITABLE VIEW

I am using table view and I am using different cell size, but when I delete the cell, it shows on constant position, not in the middle of the cell. What should I do for custom delete button position?

Upvotes: 1

Views: 1532

Answers (2)

Developer
Developer

Reputation: 107

Reload the table in viewWillAppear. It will reload the table after record has been deleted.

[super viewWillAppear:animated];
//  [self.tableView reloadData ];
[tblSimpleTable reloadData];

Upvotes: 0

tony.tc.leung
tony.tc.leung

Reputation: 2990

This is really hacky, but I found this snippet of code a while back:

- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {

        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {             

                subview.hidden = YES;
                subview.alpha = 0.0;
            }
        }
    }
}

- (void)didTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if (state == UITableViewCellStateShowingDeleteConfirmationMask || state == UITableViewCellStateDefaultMask) {
        for (UIView *subview in self.subviews) {

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {

                UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
                CGRect f = deleteButtonView.frame;
                f.origin.x -= 20;
                deleteButtonView.frame = f;

                subview.hidden = NO;

                [UIView beginAnimations:@"anim" context:nil];
                subview.alpha = 1.0;
                [UIView commitAnimations];
            }
        }
    }
}

Basically, you are peeling off the subviews until you find the delete button. What I would also suggest is to not show the default delete button and use your own custom delete button.

Upvotes: 1

Related Questions