Srinivas
Srinivas

Reputation: 983

Swipe to delete is not working with custom cell

I am using custom cell and adding tableview programmetically. I am trying to implement swipe functinality in my application. The tableview datasource method are not called when I try to swipe.

tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
tableview.delegate=self;
tableview.dataSource=self;


tableview.backgroundColor=[UIColor clearColor];
tableview.backgroundColor=selectedBackGroundColor;
tableview.separatorColor = [UIColor clearColor];


tableview.editing=YES;
NSLog(@"%f %f",self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubview:tableview];

and this method is calling

-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath 
{
    return UITableViewCellEditingStyleDelete;
}

after that even cell is also not selecting...am i missing any thing code please help me out?

Upvotes: 0

Views: 3421

Answers (4)

Srinivas
Srinivas

Reputation: 983

-(void)layoutSubviews
{
    [super layoutSubviews];
}

Then Its Working Fine.....Thanks For answering my Question

Upvotes: 8

jrturton
jrturton

Reputation: 119242

If you have set the tableview to editing already I doubt that swipe to delete (and selections if allowsSelectionDuringEditing is NO) will work at all. Try removing this line:

tableview.editing=YES;

and see if the swiping is enabled.

Upvotes: 1

user207616
user207616

Reputation:

use this implementation instead:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // Delete an object
    }   
}

Upvotes: 0

rckoenes
rckoenes

Reputation: 69469

Did you implement -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath in the datasource.

Upvotes: 1

Related Questions