自定义UITableViewCell有时不响应 [英] Custom UITableViewCell sometimes not responding

查看:61
本文介绍了自定义UITableViewCell有时不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个奇怪的问题.我想显示一个自定义单元格而不突出显示它.我的表中的 UITableViewCell 中有5个元素,如UILabel,UIImage等.问题是当我点击单元格时,有时不会显示alertview.这是我的 didSelectRowAtIndexPath 中的代码:

I am facing a weird problem. I want to display a custom cell without highlighting it. My UITableViewCell in my table has 5 elements in it like UILabel, UIImage etc. The problem is when I tap on the cell sometimes alertview is not displayed. This is the code in my didSelectRowAtIndexPath:

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:LocalizedString(@"Please input") delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            return;

我正在对此进行广泛的研究.首先,我更改了:

I was doing a wide research about it. Firsly, I changed:

cell.selectionStyle = UITableViewCellSelectionStyleNone

cell.selectionStyle = UITableViewCellSelectionStyleDefault
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor myCellColor];
[cell setSelectedBackgroundView:bgColorView];

由于我不想突出显示,因此我将单元格的突出显示颜色设置为单元格背景颜色,但是这样做的问题是,它也突出显示了分隔符.因此,当我点击分隔符的颜色时,它看起来并不好.

Since I don't want highlighting, I set the highlight color of the cell to the cell background color but the problem with that, it is highlighting the separator as well. So when I tap the color of seperator changes and it looks not nice.

我想知道如何在不使自定义单元格高亮的情况下解决此问题.

I was wondering how to solve this issue without highligthing the custom cell.

编辑注释:

didSelectRowAtIndexPath ,但不会始终显示AlertView.

didSelectRowAtIndexPath is always called but the AlertView is not always displayed.

无关紧要的UIAlertController或UIAlertView.两者有时都不会显示.

Doesn't matter simple UIAlertController or UIAlertView. Both are sometimes not displayed.

推荐答案

很可能您用一些UI组件覆盖了整个单元格,因此您无法真正触摸该单元格来执行 didSelectRowAtIndexPath 方法,请参见下面的示例图片

Most probably you covered you entire cell with some UI components so you cant really touch the cell to execute didSelectRowAtIndexPath method see example image below.

cell 的整个绿色部分,并且是 uibutton 浅蓝色:

The entire green portion of cell and is uibutton light blue:

因此,这不会每次检测到单元格上方的触摸,并正确执行 didSelectRowAtIndexPath 方法..

So this wont detect your touch everytime over cell and execute didSelectRowAtIndexPath method properly ..

希望这会有所帮助.

这篇关于自定义UITableViewCell有时不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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