在UITableView中更改移动单元格的默认图标 [英] Change default icon for moving cells in UITableView

查看:522
本文介绍了在UITableView中更改移动单元格的默认图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在UITableView中更改移动单元格的默认图标。

I need to change default icon for moving cells in UITableView.

这一个:

是否可以?

推荐答案

这是一个真正的hacky解决方案,可能无法长期运作,但可能会给你一个起点。重新排序控件是 UITableViewCellReorderControl ,但这是一个私有类,因此您无法直接访问它。但是,您可以查看子视图的层次结构并找到其imageView。

This is a really hacky solution, and may not work long term, but may give you a starting point. The re-order control is a UITableViewCellReorderControl, but that's a private class, so you can't access it directly. However, you could just look through the hierarchy of subviews and find its imageView.

您可以通过继承 UITableViewCell 并覆盖其 setEditing:animated:方法如下:

You can do this by subclassing UITableViewCell and overriding its setEditing:animated: method as follows:

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing: editing animated: YES];

    if (editing) {

        for (UIView * view in self.subviews) {
            if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) {
                for (UIView * subview in view.subviews) {
                    if ([subview isKindOfClass: [UIImageView class]]) {
                        ((UIImageView *)subview).image = [UIImage imageNamed: @"yourimage.png"];
                    }
                }
            }
        }
    }   
}






或在Swift中

override func setEditing(editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)

    if (editing) {

        for view in subviews as [UIView] {
            if view.dynamicType.description().rangeOfString("Reorder") != nil {
                for subview in view.subviews as [UIImageView] {
                    if subview.isKindOfClass(UIImageView) {
                        subview.image = UIImage(named: "yourimage.png")
                    }
                }
            }
        }
    }
}

请注意......这可能不会很长术语解决方案,因为Apple可以随时更改视图层次结构。

Be warned though... this may not be a long term solution, as Apple could change the view hierarchy at any time.

这篇关于在UITableView中更改移动单元格的默认图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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