在 UITableView 上延迟重新加载数据

发布于 2024-10-05 15:45:36 字数 344 浏览 0 评论 0原文

我有一个 UITableView。点击按钮后,我想显示我的自定义视图,然后,一旦视图可见,就从表视图中删除特定项目。自定义视图隐藏了表格视图,因此我希望在新视图可见后进行删除。

目前,我有这个,它添加了自定义视图,然后应该删除该项目,并重新加载表格,但重新加载是在动画结束时发生的(我有一个动画块,更改视图阿尔法),所以我可以看到更新。

[self.view addSubview:customView];
[itemArray removeObject:object];
[self.tableView reloadData];

如何将重新加载延迟到视图可见之后?

谢谢。

I have a UITableView. On the tap of a button i want to display my custom view, then, once the view is visible, remove a particular item from the tableview. The custom view hides the tableview so i would like the remove to occur after this new view is visible.

Currently, i have this, which adds the custom view and then should remove the item, and reload the table, but the reload is occurring just as the animation ends (i have an animation block, changing the views alpha), so i can see the update.

[self.view addSubview:customView];
[itemArray removeObject:object];
[self.tableView reloadData];

How can i delay the reload until after the view is visible?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巨坚强 2024-10-12 15:45:36

尝试将 reloadData 添加到 viewDidAppear 中:

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

这应该会给您带来所需的延迟。

Try adding reloadData to viewDidAppear:

-(void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

That should give you the required delay.

萌酱 2024-10-12 15:45:36

您提到您自己正在为视图设置动画;当动画完成时,您应该使用以下内容调用 reloadData

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(methodThatCallsReloadData)];

// or even
[UIView setAnimationDelegate:self.tableView];
[UIView setAnimationDidStopSelector:@selector(reloadData)];

或者如果您使用基于块的 API:

[UIView animateWithDuration:... completion:^(BOOL finished) {
    [self.tableView reloadData];
}];

You mention you're animating the view yourself; you should call reloadData when the animation completes by using something like:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(methodThatCallsReloadData)];

// or even
[UIView setAnimationDelegate:self.tableView];
[UIView setAnimationDidStopSelector:@selector(reloadData)];

or if you're using the block-based API:

[UIView animateWithDuration:... completion:^(BOOL finished) {
    [self.tableView reloadData];
}];
掩饰不了的爱 2024-10-12 15:45:36

或者您可以使用 PerformSelector 方法:

[self performSelector:@selector(myOtherMethod) withObject:nil afterDelay:1.5];

or you can use the performSelector method :

[self performSelector:@selector(myOtherMethod) withObject:nil afterDelay:1.5];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文