Ios 如何通过点击单元格在uitableviewcell中显示滑动按钮?

Ios 如何通过点击单元格在uitableviewcell中显示滑动按钮?,ios,objective-c,uitableview,tableviewcell,Ios,Objective C,Uitableview,Tableviewcell,我尝试通过编程手动调用这些函数,这些函数是 -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath

我尝试通过编程手动调用这些函数,这些函数是

    -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES; //tableview must be editable or nothing will work...
}
当我调用函数时,它在函数内部工作,例如EditActionsErrorWatIndeXPath函数,但不显示按钮。
如有任何线索或帮助,我们将不胜感激

您是否忘记调用
[self.tableView setEditing:YES动画:YES]

为什么使用上述3种方法来滑动和删除表格视图单元格? 只有一种方法就足够了。我为你的问题创建了一个示例。效果很好

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) IBOutlet UITableView *tableViewEdit;

@end
当我第一次运行应用程序时,它显示以下数据

然后当我滑动表视图时

最后,我删除了表视图和表视图中的数据


JA要查看我下面的回答非常感谢用户3182145,但我想在点击uitableviewcell时显示更多按钮。当我点击uitableviewcell时,我只想滑动并显示按钮,没有更多。我非常感谢您在这个问题上花费的时间。为了更清楚地理解,我想知道解决这个问题的线索,非常感谢您user3182145,但我想在点击uitableviewcell时显示更多按钮。当我点击uitableviewcell时,我只想滑动并显示按钮。为了更清楚地理解,我想知道解决这个问题的线索,我想你只能这样做。我静态创建了数据。即使它对动态数据也很有帮助。
#import "ViewController.h"

@interface ViewController (){
    NSMutableArray *arr;
}

@end

@implementation ViewController

@synthesize tableViewEdit;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    arr = [[NSMutableArray alloc]initWithObjects:@"iOS",@"Android",@"Windows",nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//UITableViewDataSource methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  arr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *strCell = @"cell";
    UITableViewCell *cell = [tableViewEdit dequeueReusableCellWithIdentifier:strCell];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
    }

    cell.textLabel.text = arr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        [arr removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
}