在我重新加载表之前,我想知道在后台保存的所有任务都已完成保存。在创建新PFQuery
之前,我必须完成5个不同的object.saveInBackgroundWithBlock({ (Success: true, error) -> Void in
count ++
})
函数。我现在的想法是说:
if
然后,一旦计数达到一定数量就可以执行查询。我不想使用 while count < 0 {
continue
} else if count == 5 {
self.fetchSecondaryObjects()
}
,因为如果网络处理保存请求的时间过长。一段时间的陈述会有效吗?如:
var prefab : GameObject;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var pos = Input.mousePosition;
pos.z = transform.position.z - Camera.main.transform.position.z;
pos = Camera.main.ScreenToWorldPoint(pos);
var q = Quaternion.FromToRotation(Vector3.up, pos - transform.position);
var go = Instantiate(prefab, transform.position, q);
go.rigidbody2D.AddForce(go.transform.up * 20000.0);
}
}
理想情况下,我会使用实时数据引擎为我的应用程序供电,但我找不到一个可以使用的功能,因为我只能在Swift中编写。如果存在,你知道它,我很想知道它。
答案 0 :(得分:0)
每次增量时都要进行检查。它的开销非常低,只有五个比较。
object.saveInBackgroundWithBlock({ (Success: true, error) -> Void in
count ++;
if count == 5 {
self.fetchSecondaryObjects()
}
})
除非我错过某些原因,否则你无法做到这一点,这似乎是最简单的解决方案。比运行无限循环更好。
答案 1 :(得分:-1)
一般情况下,我尝试不要在这种情况下使用,因为如果你的逻辑中存在某种情况,很容易陷入其中。你为什么不用这样的东西:
//
// ViewController.h
// CustomNavigationController
//
// Created by Durul Dalkanat on 11/05/15.
// Copyright (c) 2015 Durul Dalkanat. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)showLandscapeViewButtonClicked:(id)sender;
@end
//
// ViewController.m
// CustomNavigationController
//
// Created by Durul Dalkanat on 11/05/15.
// Copyright (c) 2015 Durul Dalkanat. All rights reserved.
//
#import "ViewController.h"
#import "LandscapeView.h"
#import "CustomNavigationControllerViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showLandscapeViewButtonClicked:(id)sender {
LandscapeView *landscape = [[LandscapeView alloc]initWithNibName:@"LandscapeView" bundle:nil];
CustomNavigationControllerViewController *nav = [[CustomNavigationControllerViewController alloc]initWithRootViewController:landscape];
nav.navigationBarHidden = true;
[self presentViewController:nav animated:YES completion:^{
}];
}
#pragma mark handeling rotation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
BOOL atLeastIOS6 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0;
if(atLeastIOS6)
{
return UIInterfaceOrientationMaskPortrait;
}
else{
return UIInterfaceOrientationPortrait;
}
}
@end
And Insert a New ViewController with Xib. After please change freeform.
//
// LandscapeView.h
// CustomNavigationController
//
// Created by Durul Dalkanat on 11/05/15.
// Copyright (c) 2015 Durul Dalkanat. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LandscapeView : UIViewController
@end
//
// LandscapeView.m
// CustomNavigationController
//
// Created by Durul Dalkanat on 11/05/15.
// Copyright (c) 2015 Durul Dalkanat. All rights reserved.
//
#import "LandscapeView.h"
@interface LandscapeView ()
@end
@implementation LandscapeView
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// CustomNavigationControllerViewController.m
//
//
// Created by Durul Dalkanat
//
#import <UIKit/UIKit.h>
@interface CustomNavigationControllerViewController : UINavigationController
@end
//
// CustomNavigationControllerViewController.m
//
//
// Created by Durul Dalkanat
//
#import "CustomNavigationControllerViewController.h"
@interface CustomNavigationControllerViewController ()
@end
@implementation CustomNavigationControllerViewController
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
@end