我想在Swift中实现此代码。从这些问题中,我在Objective-C中获得了以下代码:
滑动行时更改UITableViewCell中默认的红色删除按钮的颜色,或单击“编辑”按钮
- (void)willTransitionToState:(UITableViewCellStateMask)state{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
[deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
[deleteBtn release];
}
}
}
}
我不知道如何在Swift中实现此方法。有人可以帮我吗?
我正在使用Xcode 7.3 Beta。
swift tableview委托有新方法。尝试此操作可能会解决您的问题。
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?{
let ackAction = UITableViewRowAction(style: .default, title: "Himanshu", handler: myFunction)
ackAction.backgroundColor = UIColor.orange
return [ackAction]
}
现在,您甚至可以修改删除功能
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句