简体   繁体   English

UIView卡在UITableview标头后面

[英]UIView stuck behind UITableview header

In my app I have a UITableViewCell with a UITextField in it. 在我的应用程序中,我有一个带有UITextFieldUITableViewCell When the user starts typing in this textfield, an autocomplete view appears. 用户开始在此文本字段中键入时,将显示自动完成视图。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (self.suggestions != nil) {
        self.autocomplete = [[AutoComplete alloc] initWithFrame:CGRectMake(10, 53, self.frame.size.width-20, 200)];
        self.autocomplete.delegate = self;
        self.autocomplete.suggestions = self.suggestions;

        [self addSubview:self.autocomplete];
        [self bringSubviewToFront:self.autocomplete];
    }

    return YES;
}

This is nothing more than a UIView with a UITableView inside it. 这无非就是其中带有UITableViewUIView However, what happens is that this view is hidden behind the section header and the next cell. 但是,发生的是此视图隐藏在节标题和下一个单元格的后面。 在此处输入图片说明

So while it appears to be inserted above the cell, it registers the tapp below it. 因此,虽然看起来好像是在单元格上方插入了它,但是它却在其下方记录了tapp。 When you click in the autocomplete it registers the click in the next cell. 单击自动完成时,它将在下一个单元格中记录该单击。 How can I fix this? 我怎样才能解决这个问题?

Your issue is you are adding it to the view and not the tableview which resides in the UIView as well as having a section header that will probably block it out as well. 您的问题是将其添加到视图中,而不是将其添加到UIView中的tableview中,并且将其添加到节标题中也可能会将其屏蔽掉。 I see your y position is only 53, so your header is likely blocking it out. 我看到您的y位置仅为53,因此您的标题可能会将其屏蔽了。

I am not 100% sure where you want your result to be viewed and used, that's not clear in your question. 我不确定100%是否希望在哪里查看和使用结果,您的问题尚不清楚。 If you want your view to be above everything else you could: 如果您希望自己的视图高于其他一切,则可以:

  1. "I have a UITableViewCell with a UITextField in it. When the user starts typing in this textfield, an autocomplete view appears." “我有一个带有UITextField的UITableViewCell。当用户开始在此文本字段中键入内容时,将显示一个自动完成视图。” - add the result view to your cell, not the main view; -将结果视图添加到您的单元格中,而不是主视图中; [cell.contentView addSubview...
  2. Shift your tableview down by changing it's y position to self.autocomplete.view.frame.size.height . 通过将其y位置更改为self.autocomplete.view.frame.size.heightself.autocomplete.view.frame.size.height Add a nice little animation to it as it changes position too, always something that bit extra. 向它添加一个不错的动画,因为它也会改变位置,总是有些额外的东西。
  3. Consider adding it as a subview to your TableView and bringing to front, should work. 考虑将其添加为TableView的子视图并放在最前面,应该可以。

( little bit extra on the cell.contentView ) cell.contentView上的一些额外内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM