代码之家  ›  专栏  ›  技术社区  ›  ORStudios

添加到uitableview时,在情节提要中使用uitableviewcell的正确方法是什么?

  •  0
  • ORStudios  · 技术社区  · 6 年前

    希望有人能帮忙,因为我遇到了一些障碍。我从一个uiscrollview开始,它将满足于动态高度开关的输入和输出。在autolayout出现一些问题之后,我转而使用uitableview。

    目前,我在主uiview中有一个uitableview,然后在情节提要中分离uitableviewcell。每个uitableviewcell都通过iboutlet连接。

    现在要切换内容,我在重新加载数据时使用以下命令

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        if(contentToShow == 1){
    
            UITableViewCell *cell = self.cellHome;
    
            self.viewIcon1.layer.cornerRadius = 40;
            self.viewIcon1.layer.masksToBounds = true;
            self.viewIcon2.layer.cornerRadius = 40;
            self.viewIcon2.layer.masksToBounds = true;
            self.viewIcon3.layer.cornerRadius = 40;
            self.viewIcon3.layer.masksToBounds = true;
            self.viewIcon4.layer.cornerRadius = 40;
            self.viewIcon4.layer.masksToBounds = true;
    
    
            [self addUnderline:self.imageViewTitle];
            [self addUnderline:self.imageViewTitle2];
            [self addUnderline:self.imageViewTitle3];
    
            return cell;
    
        }else {
    
            UITableViewCell *cell = self.cellCustInfo;
    
            [self addUnderline:self.imageViewTitle4];
    
            return cell;
    
        }
    
    }
    

    现在,这似乎改变了uitableview的内容,但我对更改后滚动条的位置有了奇怪的问题。我正在使用以下命令尝试返回uitableview的顶部。

    - (IBAction)showFAQScreen {
    
        contentToShow = 2;
    
    
        [UIView animateWithDuration:0.4 animations:^{
            self.tableViewContent.contentOffset = CGPointZero;}];
    
        [self.tableViewContent reloadData];
    
        [self showMenu:nil];
    
    }
    

    如果滚动条没有移动,则内容显示正确;如果滚动条稍微移动,则内容按预期滚动。但是,如果滚动条显著向下移动,则滚动条会跳到底部,直到我触摸滚动条,滚动条才会自行更正。有什么想法和其他方法的建议吗?

    谢谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   Shehata Gamal    6 年前

    你能试试吗?

    UIView animateWithDuration:duration  animations:^{
      self.tableViewContent.contentOffset = CGPointZero;
    } completion:^(BOOL finished) {
         [self.tableViewContent reloadData]; 
         [self showMenu:nil];
    }];