有什么办法可以改变“DELETE"?UITableViewCell 中的按钮? [英] Is there any way to change "DELETE" button from UITableViewCell?

查看:27
本文介绍了有什么办法可以改变“DELETE"?UITableViewCell 中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 UITableViewCell 中的 DELETE 按钮.实际上,我需要:

I want to change DELETE button in UITableViewCell. Actually, I need to :

  1. 改变按钮的位置
  2. 字体
  3. 那个按钮的文字颜色.

这里我只能在以下委托方法中更改按钮文本:

Here I can only change button text in following delegate method :

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    UITableViewRowAction *viewAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Follow" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {  

        NSLog(@"View Action fired");  
    }];  
    viewAction.backgroundColor = [UIColor clearColor];  

    return @[callAction];  
}  

但是如何更改按钮的其他属性.如果有人知道,请告诉我.

But how to change other attributes of button. If anyone knows, please let me know.

谢谢.

推荐答案

要实现此功能,请在 UITableView 的委托上实现以下两个方法以获得所需的效果

To get this working, implement the following two methods on your UITableView's delegate to get the desired effect

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// you need to implement this method too esle nothing will work:

}

检查您创建的方法,您创建了 UITableViewRowAction *viewAction 的名称,但是您返回了 callAction 的值,修改一次并尝试

check your method you created the name of UITableViewRowAction *viewAction but you returned teh value of callAction modify once and try

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    UITableViewRowAction *callAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Follow" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {  

        NSLog(@"View Action fired");  
    }];  
    callAction.backgroundColor = [UIColor clearColor];  

    return @[callAction];  
}  

在标准UITableViewRowAction中我们不能改变,我们只能改变

In Standard UITableViewRowAction we can't change , we can change only

风格

标题

背景颜色

背景效果

有关更多信息,请参阅Apple 文档

这篇关于有什么办法可以改变“DELETE"?UITableViewCell 中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆