希望有人能提供帮助,因为我遇到了一些障碍。我从一个 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/