我正在使用被动ui并且我遇到了问题,主要是在我的登录方法中我想显示进度对话框,尝试登录然后关闭对话框并返回最终结果。
问题的基本伪代码是:
class GameViewController: UIViewController, ADBannerViewDelegate,
ADInterstitialAdDelegate, SKProductsRequestDelegate,
SKPaymentTransactionObserver, ChartboostDelegate, FBAdViewDelegate {
var productID: NSString!
let defaults = NSUserDefaults.standardUserDefaults()
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = false
skView.showsNodeCount = false
skView.multipleTouchEnabled = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = SKSceneScaleMode.AspectFill
//scene.size = skView.bounds.size
skView.presentScene(scene)
loadFbAds()
}
func loadFbAds() {
if defaults.boolForKey("removeAdsPurchased") == false {
let width = self.view.frame.size.width
let height = self.view.frame.size.height / 10
let adView: FBAdView = FBAdView(placementID:"placement_id", adSize:kFBAdSize320x50, rootViewController:self)
adView.frame = CGRect(x: 0, y: self.view.frame.size.height - 50, width: width, height: height)
self.view.addSubview(adView)
adView.delegate = self
FBAdSettings.addTestDevice("testdevice")
adView.loadAd()
println("worksssssssssfsdfsdfsdfsdf")
}
}
func adView(adView: FBAdView!, didFailWithError error: NSError!) {
adBannerView = ADBannerView(frame: CGRect.zeroRect)
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
adBannerView.hidden = false
view.addSubview(adBannerView)
adView.hidden = true
}
}
private IObservable<bool> AttemptLogin(CredentialPair pair)
{
return Dialogs.ShowProgress("logging in", "doing stuff...")
.SelectMany(progressController => DoTheActualLogin(pair))
.Subscribe(boolForWhetherLoginSucceeded =>
{
});
}
会返回ShowProgress
IObservable<ProgressController>
会返回DoTheActualLogIn
问题是在执行登录后,我需要针对进度控制器调用close方法。
我似乎找不到让控制器进一步顺序的方法。
我确定有一个组合器用于我缺失的序列/用于做类似事情的技术。
答案 0 :(得分:4)
我认为这就是你所追求的:
(from progressController in Dialogs.ShowProgress("logging in", "doing stuff...")
from result in DoTheActualLogin(pair)
select new { result, progressController })
.Subscribe(anon => {...}, ex => {...})
答案 1 :(得分:1)
Chris的答案很好,特别是如果你必须在链的下游使用progressController。如果你只需要在登录后进行清理,你可以这样做:
{% if wholesaler == 'True' -%}
<!-- CONTENT TO SHOW TO MEMBER OF THIS SECURE ZONE -->
{% elsif customer == 'True' -%}
<!-- CONTENT TO SHOW TO MEMBER OF THIS SECURE ZONE -->
{% else -%}
<!-- CONTENT TO SHOW TO EVERYONE ELSE -->
{% endif -%}