ios - 添加到 UITableView 时在 Storyboard 中使用 UITableViewCells 的正确方法是什么

标签 ios objective-c

希望有人能提供帮助,因为我遇到了一些障碍。我从一个 UIScrollview 开始,它包含动态高度切换的内容。在 AutoLayout 出现一些问题后,我转而使用 UITableView。

此刻我在主 UIView 中有一个 UITableView,然后在 Storyboard 中将 UITableViewCells 分开。每个 UITableViewCell 都通过 IBOutlet 连接。

现在要切换内容,我在 reloadData 上使用以下内容

- (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];

}

如果滚动没有移动,那么内容显示正确,如果它有轻微移动,那么内容按预期滚动。但是,如果滚动条明显向下移动,则滚动条会跳到底部,直到我触摸滚动条后它才会自行纠正。对正在发生的事情有什么想法以及对采取另一种方法的建议吗?

谢谢

最佳答案

你能试试吗

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

关于ios - 添加到 UITableView 时在 Storyboard 中使用 UITableViewCells 的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50815508/

相关文章:

ios - 从 NSDictionary 访问 xml 值

android - 适用于 Android 和 iOS 的 Unity3D : QR-Code Decoding (Reader)

ios - SKMapsVersioningDelegate 使用本地 maps.json 文件管理更新

objective-c - NSBlockOperation 和 NSAutoreleasePool

iphone - 初始加载时的旋转

iphone - 如何在iphone应用程序中获取经纬度的地址

ios - 收到推送通知时打开特定的标签栏

ios - 为什么尽管使用了 `insertSubview:belowSubview:`,我的 View 仍然出现在另一个 View 之上?

ios - FB token 已过期

ios - 我如何快速建立关系?