0

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?

3
  • Have added a sub? Have you added your view to the content view? Does your view automatically resizes with it parent?
    – rckoenes
    Sep 26, 2011 at 12:52
  • yes i added one lable and one image in my custom contentview
    – Srinivas
    Sep 26, 2011 at 12:54
  • i commented all labels what i added in custom cell.even thougth same. if i swipe then didselectRow ForIndexpath also not calling ...
    – Srinivas
    Sep 26, 2011 at 12:57

4 Answers 4

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

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

1
  • this was the reason of my swipe-to-delete not working....ive been banging my head with the wall for weeks...thanks alot Oct 22, 2013 at 10:08
1

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

1

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.

0

use this implementation instead:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.