自定义UITableViewCell中的按钮在iOS 7中不响应

马修·克拉克

这或多或少是本文的延续:UITableViewCell中的按钮在ios 7下不响应

我有相同的确切问题,并尝试了线程中的每个建议。显然,我不拥有该问题,因此无法对其进行编辑以提供更多信息,因此,为什么我现在要发布此问题!

问题:

我加载的VC nib具有一个tableview,可根据其中的行数来调整大小。每行都是使用nib文件从自定义uitableviewcell子类生成的。该班级/笔尖有4个按钮。我现在可以在iOS 6或iOS 8中加载此代码,并且可以完美运行。我没有iOS 7设备,所以我必须绑定到7.1版的模拟器(这是我认为报告此问题的用户使用的版本,与今天一样)。现在,在模拟器和用户的电话中,我可以触摸/单击该VC上除单元格中任何按钮之外的所有其他内容。好像他们已UserInteractionEnabled设置为NO,但它们没有,并且它们也不是任何父视图(因为我很快就会讲到)。

尝试过的解决方案:

-使用和不使用自动布局完全重新创建笔尖

-Calling[self.contentView addSubview:button]awakeFromNib细胞类

-尝试contentView在运行时将按钮重新添加到[self.contentView addSubView:button]

-已确保遍历四次,可以发现导致这些按钮的层次结构中的每个视图均userInteractionEnabled设置为YES。(包括但不限于表格contentView视图本身,单元格,以及当我向设置的按钮添加“父视图”时也是如此)

-尝试使用父视图引发所有按钮,该视图仅包含按钮

-所有按钮都位于事件堆栈的顶部(视觉上位于底部)(添加和删除是其他两个按钮): 层次结构清单

-已将表格单元格选择从单个设置为无。

-layoutSubviews我的单元课没有压倒一切

-我无法将任何视图移出Content View,因为如果这样做,Interface Builder会将其完全移出单元格。

-我曾试图禁止userInteractionEnabled上只是ContentView没有在运行时改变

-我尝试将表格视图的单元格创建代码放入[cell bringSubviewToFront:cell.button];不同按钮以得到相同的结果。

希望有帮助的事实:

-我尝试将层次结构中所有视图的所有背景色设置为不同的颜色,以便可以在运行时直观地对其进行调试...它看起来完全符合预期。没有重叠或覆盖。(这仅限于单元格中的视图)

-这是TableView的所有设置: TableView SS 1 TableView SS 2

-我尝试将其加载到新的XCode 6中以使用可视调试器,但其中随附的7.1仿真器实际上完美地运行了代码,因此我可以对其进行调试...

-Here is the dequeueing code in the VC:

NiTGroupTimeCell* cell = (NiTGroupTimeCell*)[tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

-Here is the code in the viewDidLoad of the VC to set up the cell nib with the table(it's 2 because this is the from scratch one):

[self.timesTable registerNib:[UINib nibWithNibName:@"NiTGroupTimeCell2" bundle:nil]  forCellReuseIdentifier:@"GroupTime"];

-All connections were made via IB. These are all using IBAction or IBOutlet.

-I have NSLog statements in all button methods to test if they are actually called, but I have also tested with breakpoints. All are never triggered in testing.

-The only TableView delegate or datasource methods implemented are as follows:

-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

-As per suggestion I took Revel to it and found that a mystery UILabel and UIImageView were in the view.... but as you can see their frames are all zeros so they shouldn't be getting in the way of anything so back to where we were I'm afraid:

层数

Hierarchy List from Revel

UILabel frame: UILabel frame

UIImageView frame: UIImageView frame

IIRC我之前认为这是一个模拟器错误,但是由于它是在用户设备上发生的,因此这必须是一个实际问题,并且它阻碍了我的工作流程,因此将非常感谢您的帮助!提前致谢!

PS我很乐意发布任何内容,但是由于调试方面的所有变化,我不知道确切地人们会想看到什么,并且我不想超载这篇文章,因为我知道这将花费很多时间其他。

马修·克拉克

所以显然问题是这些代码行(来自我的git diff输出的diff格式):

--(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
+-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

--(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
+-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

所以,是的。。。似乎在iOS7 +中,如果您为这些数据源方法使用“旧”输出类型,它看起来会很好,但功能上却使您的表视图...好时机,但嘿,现在已修复^^希望对其他人有所帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章