viewDidAppear for UITableViewCell

和自甴很熟 提交于 2019-12-03 08:17:06

问题


I usually use viewDidAppear method 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 UITableViewCell after it finished appearing, is there any available method in the SDK that does a similar job like viewDidAppear but for UITableViewCell ?

p.s. willDisplayCell did not work in my case, I need something like didDisplayCell if it really exists.


回答1:


The UITableViewDelegate has these functions:

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.




回答2:


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




回答3:


The method viewDidLoad is 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 layoutSubViews method of UITableViewCell, and I delayed the action for some time as below.

- (void)layoutSubViews
{
     [super layoutSubviews];

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


来源:https://stackoverflow.com/questions/10772272/viewdidappear-for-uitableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!