Ios refreshControl扩展在imagePicker之后不显示微调器
我编写了一个扩展,允许我在UIViewController中的常规tableView上显示refreshControl。下面的代码在viewDidLoad()上以及拉入刷新时可以完美地工作 扩展名:Ios refreshControl扩展在imagePicker之后不显示微调器,ios,swift,uitableview,extension-methods,uirefreshcontrol,Ios,Swift,Uitableview,Extension Methods,Uirefreshcontrol,我编写了一个扩展,允许我在UIViewController中的常规tableView上显示refreshControl。下面的代码在viewDidLoad()上以及拉入刷新时可以完美地工作 扩展名: extension UITableView { func findRefreshControl () -> UIRefreshControl? { for view in subviews { if view is UIR
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()
}
}
_ = presenter.profilePictureUploadingPending.skip(first: 1).observeNext { _ in self.showLoader() }
_ = presenter.profilePictureUploaded.skip(first: 1).observeNext { _ in self.hideLoader() }
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())
}
}
}
视图控制器中的被调用方:(通过观察事件触发结束)
观察员:
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()
}
}
_ = presenter.profilePictureUploadingPending.skip(first: 1).observeNext { _ in self.showLoader() }
_ = presenter.profilePictureUploaded.skip(first: 1).observeNext { _ in self.hideLoader() }
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())
}
}
}
但是,当我进入UIImagePicker在我的应用程序中上载照片并返回到viewController时,它会再次触发旋转过程,直到照片成功上载
我调试了我的代码,它正在启动方法,但微调器从视图层次结构子视图中消失,并且没有显示
我不知道如何解决这个问题,但我真的很感谢你们的帮助
谢谢,
凯文。用以下解决方案解决:
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()
}
}
_ = presenter.profilePictureUploadingPending.skip(first: 1).observeNext { _ in self.showLoader() }
_ = presenter.profilePictureUploaded.skip(first: 1).observeNext { _ in self.hideLoader() }
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())
}
}
}
使用以下解决方案解决:
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()
}
}
_ = presenter.profilePictureUploadingPending.skip(first: 1).observeNext { _ in self.showLoader() }
_ = presenter.profilePictureUploaded.skip(first: 1).observeNext { _ in self.hideLoader() }
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())
}
}
}