UITableView自定义UIView重复

Ign*_*oná 9 objective-c uitableview table-footer

因此,客户的规范要求UITableView始终存在其中一行,因此用户可以在UITableView的任何位置与此关键按钮进行交互.一旦他滚动并通过按钮看到实际的Row,浮动页脚必须消失并允许用户与"真实"Cell进行交互,而不是浮动版本.

我想出了以下代码:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{    
    if([self isPostularmeRowVisible])
    {
        [self hidePostularmeFooterView];
    }
    else
    {
        [self showPostularmeFooterView];
    }
}

-(BOOL)isPostularmeRowVisible
{        
    NSArray *indexes = [self.tableView indexPathsForVisibleRows];
    for (NSIndexPath *index in indexes)
    {
        if (index.row == 0 && index.section>=DetalleEmpleoPostularmeCell)
        {
            return YES;
        }
    }
    return NO;
}

-(void) showPostularmeFooterView
{
    NSAssert(_state==ESTADO_POSTULACION_NO_POSTULADO, @"NJDetalleEmpleoViewController: This shouldn't happen");

    if(!self.footerView)
    {
        NJDetalleEmpleoPostularmeTableViewCell *footerView = [self.tableView dequeueReusableCellWithIdentifier:kDetalleEmpleoPostularmeCell];
        [footerView configureCell:self.detaleAviso];
        float h = self.view.frame.size.height-footerView.cellHeight;
        footerView.frame = CGRectMake(0,h,self.view.frame.size.width,footerView.cellHeight);
        footerView.delegate = self;
        self.footerView = footerView;
        [self.view addSubview:self.footerView];
        [self.view bringSubviewToFront:self.footerView];
    }
}

-(void) hidePostularmeFooterView
{
    if(self.footerView)
    {
        [self.footerView removeFromSuperview];
    }

    self.footerView = nil;
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码有一个我似乎无法弄清楚的错误:一旦用户点击UITextBox并输入一些文本就开始表现不正常,即:2个或更多Cell出现在屏幕上,什么时候应该没有!基本上,当我调用方法'hidePostularmeFooterView'时,它似乎没有消失(只有在我输入一些文本后,如果我不与它交互,它就可以正常工作).

在此输入图像描述

在我输入一些文本后,似乎有2个版本的页脚,这里是证据:

在此输入图像描述

ric*_*itz 5

你可能更有意义的是将它作为单元格和页脚删除并将其替换为它自己的UIView下方UITableView,并且UITableView框架高度仅降低到该视图的y原点,而不是占据整个屏幕.这样,您就可以随时查看视图并与其进行交互.你有什么理由需要这个UITableViewCell吗?


Joh*_*kex 3

在此输入图像描述

我不会触摸 footerView,而是创建一个出现的自定义视图,如下所示:

dataSource = [NSMutableArray new];
for (int n = 0; n < 100; n++){
    [dataSource addObject:[NSString stringWithFormat:@"%i",n]];
}

table = [UITableView new];
table.frame = self.view.bounds;
table.delegate = self;
table.dataSource = self;
[self.view addSubview:table];

popUpView = [UIImageView new];
popUpView.frame = CGRectMake(0, h-200, w, 200);
popUpView.image = [UIImage imageNamed:@"Grumpy-Cat.jpg"];
popUpView.contentMode = UIViewContentModeScaleAspectFill;
popUpView.clipsToBounds = true;
popUpView.layer.borderColor = [UIColor redColor].CGColor;
popUpView.layer.borderWidth = 2.0f;
[self.view addSubview:popUpView];
Run Code Online (Sandbox Code Playgroud)

像往常一样设置 tableView,并在scrollViewDidScroll 方法中,您可以粘贴如下内容:

NSIndexPath * specialRow = [NSIndexPath indexPathForRow:50 inSection:0];
NSArray * indices = table.indexPathsForVisibleRows;
if ([indices containsObject:specialRow]){
    if (isShowing){
        isShowing = false;
        [UIView animateWithDuration:1.0f
                              delay:0.0f
             usingSpringWithDamping:1.0f
              initialSpringVelocity:0.8f
                            options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                             popUpView.transform = CGAffineTransformMakeTranslation(0, popUpView.frame.size.height + 10);
                         }
                         completion:^(BOOL finished){
                         }];
    }
} else if (!isShowing) {

    isShowing = true;
    [UIView animateWithDuration:1.0f
                          delay:0.0f
         usingSpringWithDamping:1.0f
          initialSpringVelocity:0.8f
                        options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         popUpView.transform = CGAffineTransformIdentity;
                     }
                     completion:^(BOOL finished){
                     }];
}
Run Code Online (Sandbox Code Playgroud)

其中 isShowing 是一个布尔值,用于跟踪 popUpView 状态。这是快速而肮脏的代码,应该在其他地方声明specialRow等。在本例中,它被定义为 100 行中的第 50 行。

根据记录,我认为拥有这样的重复功能不是一个好的设计,但是嘿,客户最了解:D