ios - refreshControl 扩展在 imagePicker 之后不显示微调器

标签 ios swift uitableview extension-methods uirefreshcontrol

我写了一个扩展,允许我在 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 时,它应该再次触发旋转过程,直到照片成功上传。

我调试了我的代码,它正在启动方法,但是微调器从 View 层次结构 subview 中消失并且没有显示...

我不确定如何解决这个问题,但我非常感谢你们的帮助!

谢谢, 凯文。

最佳答案

通过以下解决方案解决:

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())
            }
        }
    }

关于ios - refreshControl 扩展在 imagePicker 之后不显示微调器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43381619/

相关文章:

swift - 如何让 UIButton 按下以在 Swift 中的 UICollectionViewCell 中工作?

ios - ARKit 遮挡不可见平面引用图像

swift - 如何从 TableView 的值动态打印 UILabel 中的值

Xcode 6.3 解析 SDK 1.7.1 PFTableViewCell 错误 "has incompatible type"

ios - 如何使用 NSXMLParser 从 SWIFT 中的 XML 获取特定属性

ios - 生成声音(不是来自文件)

ios - Firebase 电话身份验证错误 FIRAuthErrorCodeMissingAppToken

ios - 准备 segue : Cannot convert value of type 'UIViewController' to specified type 'SecondViewController'

iphone - 根据内容更新 UITableViewCell 的编辑样式

iphone - CoreData 连接实体进行排序