【发布时间】:2017-09-08 22:44:25
【问题描述】:
我编写了一个扩展程序,允许我在 UIViewController 中的常规 tableView 上显示 refreshControl。下面的代码在 viewDidLoad() 和拉刷新时完美运行。
扩展:
extension UITableView
{
func findRefreshControl () -> UIRefreshControl?
{
for view in subviews
{
if view is UIRefreshControl
{
print("The refresh control: \(view)")
return view as? UIRefreshControl
}
}
return nil
}
func addRefreshControlWith(sender: UIViewController, action: Selector, view: UIView)
{
guard findRefreshControl() == nil else { return }
let refreshControl = UIRefreshControl()
refreshControl.addTarget(sender, action: action, for: UIControlEvents.valueChanged)
view.addSubview(refreshControl)
}
func showRefreshControlWith(attributedTitle: String? = nil)
{
findRefreshControl()?.attributedTitle = NSAttributedString(string: attributedTitle!)
findRefreshControl()?.beginRefreshing()
}
func hideRefreshControl ()
{
findRefreshControl()?.endRefreshing()
}
}
ViewController 中的被调用者:(通过观察事件触发)
private func showLoader()
{
tableView.showRefreshControlWith(attributedTitle: "Loading Profile".localized())
}
private func hideLoader()
{
tableView.hideRefreshControl()
}
观察者:
_ = presenter.profilePictureUploadingPending.skip(first: 1).observeNext { _ in self.showLoader() }
_ = presenter.profilePictureUploaded.skip(first: 1).observeNext { _ in self.hideLoader() }
但是,当我进入 UIImagePicker 以在我的应用中上传照片并返回到 viewController 时,它应该再次触发旋转过程,直到照片上传成功。
我调试了我的代码,它正在启动方法,但微调器从视图层次结构子视图中消失了,并且没有显示出来......
我不确定如何解决这个问题,但我非常感谢你们的帮助!
谢谢, 凯文。
【问题讨论】:
标签: ios swift uitableview extension-methods uirefreshcontrol