ios - 添加到 UITableView 时在 Storyboard 中使用 UITableViewCells 的正确方法是什么
问题描述
希望有人可以提供帮助,因为我遇到了一些障碍。我从一个 UIScrollview 开始,它包含动态高度切换的内容。在 AutoLayout 出现一些问题后,我转而使用 UITableView。
目前我在主 UIView 中有一个 UITableView,然后在情节提要中分离 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];
}];
推荐阅读
- python - 如何根据搜索特定列中的数据在 Pandas Dataframe 中选择一行
- node.js - 节点 js:无法运行 socket.io
- jenkins - 在构建过程中使用 Jenkinsfile 修改现有文本文件
- next.js - 如何使用 Next.js 应用程序在 Vercel(以前称为 Zeit Now)中安排 npm run build 每小时调用一次
- c# - 包含 GridSplitter-s 的 Grid 内的边框与所有后续行重叠
- javascript - Node js定义响应有效负载结构
- java - Java MapDB:如何处理“已经打开”的异常?
- mysql - 创建一个 MySQL 视图以获取计数列的平均值
- python - python中的父子循环
- javascript - 如何打开像脸书一样的推特弹出窗口