大佬教程收集整理的这篇文章主要介绍了ios – 没有调用RxSwift订阅块,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class Gallerymodel { var galleryCount: BehaviorSubject<Int> init() { galleryCount = BehaviorSubject.init(value:0) } func refresh() { doAsyncrequestToAmazonWithCompletion { (responsE) -> AnyObject! in var counter = 0 //process response counter = 12 dispatch_async(dispatch_get_main_queue()) { self.galleryCount.on(.Next(counter)) } return nil } } class ViewController: UIViewController { @IBOutlet weak var label: UILabel! var gallerymodel: Gallerymodel? override func viewDidLoad() { super.viewDidLoad() gallerymodel?.galleryCount.subscribe { e in if let gc = e.element { self.label.text = String(gC) } } } } class AppDelegate: UIResponder,UIApplicationDelegate { var gallerymodel: Gallerymodel? func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { //do amazon setup gallerymodel = Gallerymodel() if let viewController = window?.rootViewController as? ViewController { viewController.gallerymodel = Gallerymodel() } return true } func applicationDidBecomeActive(application: UIApplication) { gallerymodel?.refresh() }
标签只更新一个,显示“0”.我希望标签更新两次,在第一次更新后显示“0”,在处理网络请求后第二次更新后显示“12”. dispatch_async块中的断点被命中,但似乎galleryCount丢失了它的观察者.有人知道发生了什么或如何调试这个?
最好
以上是大佬教程为你收集整理的ios – 没有调用RxSwift订阅块全部内容,希望文章能够帮你解决ios – 没有调用RxSwift订阅块所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。