ios - 更改 UITableViewCell ios 7.1.2 中默认删除按钮的颜色

标签 ios uitableview ios7.1

我开发了一个应用程序。并更改了删除按钮的默认红色。它工作得很清楚。但是在我升级我的 iPad iOS 7.1.2 之后,它不再起作用了。 这是我使用过的代码

 for (UIView *subview in self.subviews) {
        for(UIView *subview2 in subview.subviews){
            if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"] ||) {
                ((UIView*)[subview2.subviews firstObject]).backgroundColor=[UIColor blueColor];
            }
        }
    }

最佳答案

问题是您试图在错误的时间访问 UITableViewCellDeleteConfirmationButton

Apple 似乎更改了实现方式,以便在触发 willTransitionToState: 和触发 didTransitionToState: 之前实际构造按钮并将其添加到 View 层次结构中

访问 didTransitionToState: 中的按钮为时已晚。它会在拖动时保持其原始颜色,并且只有在您完成滑动时才会更改颜色。

解决方法是在线程的运行循环中对方法进行排队,而不是立即执行它,同时允许操作系统添加删除按钮 View 。

- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        [self performSelector:@selector(setupDeleteButton) withObject:nil afterDelay:0];
    }
}

- (void)setupDeleteButton
{
    [self recurseToDeleteButtonInViews:[self subviews]];
}

- (void)recurseToDeleteButtonInViews:(NSArray *)subviews
{
    for (UIView *subview in subviews)
    {
    if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"]){
            // You just found your button!
            // Do what ever you want with it!
            return;
        }
        if ([[subview subviews] count] > 0){
            [self recurseToDeleteButtonInViews:[subview subviews]];
        }
    }
    return;
}

附注此代码不向后兼容 iOS 6.0,因为按钮 View 的名称在 iOS 7 中已更改

关于ios - 更改 UITableViewCell ios 7.1.2 中默认删除按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24628243/

相关文章:

ios - 打开 safari 后终止应用程序 - swift

ios - 直接在导航栏下方滚动表格 View 单元格?

ios - 通过添加 subview 将数据传递到自定义 UITableViewCell

ios - 每个部分中选择的项目数

ios - 比较 iOS7.1 上损坏的 JSON 数据

ios - MapKit 和谷歌地图

ios - 如何在 iPad 的 UISplitViewController 中隐藏 MasterViewController

ios - MonoTouch : How to download pdf incrementally as indicated in the Apple slides "Building Newsstand Apps", session 504?

ios - 无法隐藏自定义 subview

ios - Spritekit 节点在移动时会抖动……为什么?