滑动以删除不适用于自定义单元格

时间:2011-09-26 12:24:37

标签: iphone ios uitableview

我正在使用自定义单元格并以程序方式添加tableview。我正在尝试在我的应用程序中实现滑动功能。当我尝试滑动时,不会调用tableview数据源方法。

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];

并且此方法正在调用

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

之后,偶数单元格也没有选择...我错过任何代码请帮帮我吗?

4 个答案:

答案 0 :(得分:8)

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

然后它的工作正常.....感谢您回答我的问题

答案 1 :(得分:1)

您是否在数据源中实现了-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

答案 2 :(得分:1)

如果您已将表格视图设置为editing,我怀疑是否可以滑动删除(以及allowsSelectionDuringEditingNO时的选择)。尝试删除此行:

tableview.editing=YES;

并查看是否启用了滑动功能。

答案 3 :(得分:0)

改为使用此实现:

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