【问题标题】:refreshControl extension does not show spinner after imagePickerrefreshControl 扩展在 imagePicker 之后不显示微调器
【发布时间】: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


    【解决方案1】:

    通过以下解决方案解决:

    private func showLoader()
        {
            DispatchQueue.global(qos: .default).async {
                DispatchQueue.main.async {
                    self.tableView.contentOffset.x = 1
                    self.tableView.contentOffset.y = -81
                    self.tableView.showRefreshControlWith(attributedTitle: "LOADING_PROFILE".localized())
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      相关资源
      最近更新 更多