ios UITableViewCell 的 viewDidAppear

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10772272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:30:56  来源:igfitidea点击:

viewDidAppear for UITableViewCell

iphoneobjective-ciosuitableviewviewdidappear

提问by JAHelia

I usually use viewDidAppearmethod to do some UI stuff on the view after it finished appearing and I used this method in various situations were it was very useful, however, I need to do some UI changes on a UITableViewCellafter it finished appearing, is there any available method in the SDK that does a similar job like viewDidAppearbut for UITableViewCell?

我通常viewDidAppear在视图出现后使用方法在视图上做一些UI东西,我在各种情况下都使用了这个方法,它非常有用,但是,我需要在它出现后在视图上做一些UI更改UITableViewCell,有没有可用的SDK 中的方法执行类似的工作,viewDidAppear但对于UITableViewCell?

p.s. willDisplayCelldid not work in my case, I need something like didDisplayCellif it really exists.

pswillDisplayCell在我的情况下不起作用,didDisplayCell如果它真的存在,我需要一些东西。

回答by neoneye

The UITableViewDelegatehas these functions:

UITableViewDelegate具有以下功能:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)

The cell itself does not have callbacks for this.

单元本身没有回调。

回答by Mike Weller

If you need to respond to changes to the cell's frame and adjust the layout, you need to implement -layoutSubviewsin the cell class. Remember to call [super layoutSubviews].

如果需要响应cell的frame的变化和调整布局,需要-layoutSubviews在cell类中实现。记得打电话[super layoutSubviews]

回答by Ganesh

The method viewDidLoadis related to UIViewController and its subclasses, so we cannot use this in UITableViewCell, which is a UIView subclass. The solution I used in one of my app is to override the layoutSubViewsmethod of UITableViewCell, and I delayed the action for some time as below.

该方法viewDidLoad与 UIViewController 及其子类有关,因此我们不能在 UITableViewCell 中使用它,它是 UIView 的子类。我在我的一个应用程序中使用的解决方案是覆盖layoutSubViewsUITableViewCell的方法,并且我将操作延迟了一段时间,如下所示。

- (void)layoutSubViews
{
     [super layoutSubviews];

     [self performSelector:@selector(myMethod) withObject:nil afterDelay:1.0];
}