问题描述
我有一个弹出窗口,里面有:
I have a popover screen, with inside it :
- 一个标签,可能出现也可能不出现(标题)
- 一个搜索栏,可能出现也可能不出现
- 一个标签,可能出现也可能不出现,且高度可变(帮助标签)
- 滚动视图,可能出现也可能不出现,并且具有可变高度(关于下表的一些信息)
- 表格视图
- a label, that may or may not appear (title)
- a search bar, that may or may not appear
- a label, that may or may not appear, and has a variable height (help label)
- a scrollview, that may or may not appear, and has a variable height (some infos about the following table)
- a table view
为了呈现一些不错的东西,在 viewDidLoad
中,我移动各种框架以放置对象正确,没有未使用的空格混乱我的弹出窗口。此外,我然后调整表的大小(以占据最需要的位置),并通过 contentSizeInPopover
弹出窗口(以避免有一个近乎空的巨大弹出窗口)。所有调整大小似乎很好,但我有一个大问题:所有调整大小完成后,我的UITableView的一些单元格变得无法响应。一个或两个单元格,通常是第二个单元格,只有在我的外角点击时才会响应,但是单元格的其余部分完全忽略任何触摸。
In order to present something nice, in viewDidLoad
, I move the various frames to place the objects correctly and not have unused spaces cluttering my popover. Besides, I then resize the table (to take the most place needed), and the popover via contentSizeInPopover
(to avoid having a near-empty huge popover). All that resizing seems to work nicely, but I have one big problem : with all that resizing done, some cells of my UITableView become unresponsive. One or two cells, usually the second one, only respond if i tap in their outer corners, but the rest of the cell completely ignore any touches.
我试过了一切:全部移动到 viewWillAppear
,让autoresize完成它的工作(似乎也没有工作),但我每次都有这个问题。我发现如果我评论涉及更改表的 frame
或 contentSizeInPopover
中的行,问题停止了,但后来我的观点搞砸了,所以这不是一个修复。
I've tried everything : moving all to viewWillAppear
, letting the autoresize do its job (doesn't seem to work either), but I still have this problem every time. I've found that if I comment the lines involved with changing the frame
of the table, or the ones in contentSizeInPopover
, the problem stops, but then my view is messed up, so this ins't a fix.
如果有人能给我一些东西摆脱这个烂摊子,那个会很棒。
If anyone could give me something to get out of this mess, that would be awesome.
- (CGFloat)getHeightWithoutTable {
return LIST_TITLE_HEIGHT + (self.searchBar.hidden ? 0 : LIST_SEARCH_BAR_HEIGHT) + (self.helpLabel.hidden ? 0 : self.helpLabel.frame.size.height + LIST_STD_SPACE) + (self.errorScrollView.hidden ? 0 : self.errorScrollView.frame.size.height + LIST_STD_SPACE);
}
-(void)viewDidLoad {
[super viewDidLoad];
self.tableViewOutlet.backgroundView = nil;
self.originData = [NSMutableArray array];
self.searchedData = [NSMutableArray array];
if (self.helper != nil) {
CGFloat heightOffset = 0;
// Content
self.originData = [self.helper getData];
self.tableData = [NSMutableArray arrayWithArray:self.originData];
// Title
NSString *title = [self.helper getPopoverTitle];
if (title == nil) {
self.popoverTitle.hidden = YES;
heightOffset -= LIST_TITLE_HEIGHT;
} else {
self.popoverTitle.text = [self.helper getPopoverTitle];
}
// Search
if ([self.originData count] [self getStdHeight] / 3){
self.helpLabel.lineBreakMode = UILineBreakModeTailTruncation;
[self.helpLabel sizeThatFits:CGSizeMake(self.helpLabel.frame.size.width, [self getStdHeight] / 3)];
}
heightOffset += (self.helpLabel.frame.size.height - LIST_HELP_STD_HEIGHT);
}
// Errors
if ([self.helper respondsToSelector:@selector(getErrors)]) {
self.errors = [self.helper getErrors];
}
if (self.errors == nil || [self.errors count] == 0) {
self.errorScrollView.hidden = YES;
self.errorBg.hidden = YES;
heightOffset -= LIST_ERROR_STD_HEIGHT + LIST_STD_SPACE;
} else {
[self createErrorView];
heightOffset += (self.errorScrollView.frame.size.height - LIST_ERROR_STD_HEIGHT);
}
// Table
CGFloat previewHeight = LIST_CELL_HEIGHT * [self.tableData count] + LIST_STD_SPACE;
CGFloat remainingHeight = LIST_MAX_HEIGHT - [self getHeightWithoutTable] - LIST_STD_SPACE;
CGFloat tableHeight = MIN(previewHeight, remainingHeight);
CGRect tableFrame = self.tableViewOutlet.frame;
self.tableViewOutlet.frame = CGRectMake(tableFrame.origin.x, tableFrame.origin.y + heightOffset, LIST_WIDTH, tableHeight);
// Selected items
if ([helper getSelectedObject] != nil){
int index = [self.tableData indexOfObject:[helper getSelectedObject]];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
[self.tableViewOutlet scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
}
- (CGSize)contentSizeForViewInPopover {
if (self.navigationController) {
return CGSizeMake(LIST_WIDTH, LIST_MAX_HEIGHT);
} else {
CGFloat totalHeight = [self getHeightWithoutTable] + self.tableViewOutlet.frame.size.height + LIST_STD_SPACE;
return CGSizeMake(LIST_WIDTH, totalHeight);
}
}
(如果你需要一些着色来帮助你)
(gist if you need some coloring to help you)
笔尖的图像:
推荐答案
自己找到答案:我在UITableView旁边使用自填UIScrollView的事实似乎是问题所在。一旦我用适当的UITableView替换了UIScrollView,问题就消失了。
Found the answer myself : the fact I was using a self-filled UIScrollView next to my UITableView seemed to be the problem. As soon as I replaced the UIScrollView by a proper UITableView, the problem disappeared.
这篇关于UITableViewCell变得无法响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!