Hardik Patel
Hardik Patel

Reputation: 116

Change position of UITableViewCellEditingStyle

How can I change the deletion button position when using UITableViewCellEditingStyle from right to left?

Upvotes: 6

Views: 870

Answers (5)

Harish
Harish

Reputation: 609

You cannot change the position of the native delete button ON the place the default delete button use custom button make them hide .On the click of edit button make them visible .For creating the button , Use this formate it will solve your problem write this code in your cellforrowAtindexPath method

UIButton*Delete_btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [Delete_btn addTarget:self action:@selector(Delete:) forControlEvents:UIControlEventTouchUpInside];
        Delete_btn.frame = CGRectMake(05, 10, 56, 56);
        [Delete_btn setBackgroundImage:[UIImage imageNamed:@"delete_btn.png"] forState:UIControlStateNormal];
        [cell.contentView addSubview:Delete_btn];

Upvotes: 1

Rahul Mathur
Rahul Mathur

Reputation: 882

You can use a custom button in you storyboard/xib and then use [*buttonObject addTarget] method to know the click event. This is the easiest way to customise your tableview without using native accessories .

Upvotes: 0

6rod9
6rod9

Reputation: 1457

You cannot change the position of the native delete button. You can subclass UITableViewCell and create the button yourself, placing it(hidden) on the left edge, and in the buttons callback move the cell content to the right.

Upvotes: 0

amitshinik
amitshinik

Reputation: 91

There is no in-built method for changing position of Deletion button in UITableViewCell. You should make a custom class which is subclass of UITableViewCell and make UI of cell with XIB or code whatever you choose and also gave proper outlets and actions to the cell elements.

Upvotes: 0

sanjaymathad
sanjaymathad

Reputation: 232

You can subclass UITableViewCell, add a delete button and add a uiview on top of the button in the content view of the cell. Code will be like this for adding the subviews in cell class

[self.contentView addSubView:button];
[self.contentView insertSubview:view aboveSubview:button];

Add swipe gesture to the uiview making swipe direction right. When button is clicked, you can add a delegate to send back to the controller to delete the cell and reload table. You can also do it with help of the nib file by placing delete button first and then uiview. Hope it helps.

Upvotes: 0

Related Questions