我创建了一个自定义的 PushViewController 方法,在转换完成后会进行回调。它可以在应用程序上运行,但不能使其在单元测试中运行。这是 UINavigationController 扩展:
extension UINavigationController {
public func pushViewController(_ viewController: UIViewController, animated: Bool, completion: @escaping (Void) -> Void) {
pushViewController(viewController, animated: animated)
guard animated, let coordinator = transitionCoordinator else {
completion()
return
}
coordinator.animate(alongsideTransition: nil) { _ in completion() }
}
}
Run Code Online (Sandbox Code Playgroud)
当我在单元测试中调用它时transitionCoordinator总是为零。我尝试设置一个窗口,将导航设置为根控制器,并使该窗口键可见。我也尝试过访问视图属性,以便加载 VC,但似乎没有任何效果。transitionCoordinator财产永远为零。
有任何想法吗?这是单元测试的预期行为吗?
我试图在我的swift应用程序中找到内存问题.通过检查是否调用deinit找到了一些(例如代理中的强引用)但是检查UITableViewCell或UICollectionViewCell我没有看到deinit从未被调用.
我有一个非常简单的单元格,我使用:
更新:
检查tableView是否正在调用它的deinit,但事实并非如此.所以UIViewController调用它的deinit但是tableView仍在内存中.
更新2:
发现了这个问题.一个后卫让我们在辅助函数中保持对tableView的强引用.
我正在开始一个Meteor项目,我想在不同的页面上使用不同的body css类.如果我向身体添加一个css类,我得到:
Attributes on <body> not supported
Run Code Online (Sandbox Code Playgroud)
我发现的唯一方法是使用JS添加类.有一个更好的方法吗?