Custom UIButton inside a UITableView keeps highlighted after being pressed
我已经实现了一个自定义 UIButton,发布在 cocoacontrols.com:
http://cocoacontrols.com/platforms/ios/controls/imageless-gradient-buttons
我?'刚刚将项目转换为 ARC 并设置了按钮。它们可以工作,但在按下一次后,它们会保持高亮渐变。
为了设置它们,我只是更改了故事板和 IBOutlets 上的类,并且我已经在 viewDidLoad 上选择了我想要的渐变。
知道可能是什么问题吗?
编辑:我花了更多的时间在它上面,似乎只有当按钮位于 UITableView 上时才会出现问题。当它在 UIViewController
上时它工作正常
EDIT #2:根据 NSLogs,当容器是 UIViewController 时,按下按钮时渐变会恢复正常:
1 2 3 | 2012-05-26 10:53:17.950 GradientButtons[11507:f803] highlighthed 2012-05-26 10:53:18.040 GradientButtons[11507:f803] highlighthed 2012-05-26 10:53:18.140 GradientButtons[11507:f803] Normal |
但是当容器是 UTableViewController 时,按钮保持高亮渐变:
1 2 | 2012-05-26 10:55:20.969 GradientButtons[11507:f803] highlighthed 2012-05-26 10:55:21.069 GradientButtons[11507:f803] highlighthed |
我检查了 viewContentMode,所有按钮、UIView 和 UITableView(缩放以填充)都是一样的。将其更改为重绘不会改变行为。
有负责正常/高亮渐变绘制的检查:
1 2 3 4 | if (self.state == UIControlStateHighlighted) gradient = self.highlightGradient; else gradient = self.normalGradient; |
需要设置断点或添加NSLog\\'s,看看那里是否选择了正常渐变。如果没有,下一步是覆盖普通的 UIButton
根据您的日志,我发现它很有趣并重现了该问题,它似乎是在
1 2 3 4 5 6 | -(void) setHighlighted:(BOOL)highlighted { NSLog(@"setHighlighted %@", highlighted ? @"Y": @"N"); [super setHighlighted:highlighted]; [self setNeedsDisplay]; } |