开发者

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.

table开发者_如何学运维view = [[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?


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

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


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


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.


use this implementation instead:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜