あるメソッドから別のメソッドにある UIView を呼び出して閉じようとしています。UIView は正常に閉じますが、現在のメソッドですべてのプロセスが終了するまでは閉じません。
最初のことを最初に強制的に発生させる方法があるかどうか (つまり、UIview を閉じる)、現在の方法を続行する方法があるかどうかを知りたいですか?
これは私の方法がどのように見えるかです
- (void)selectDeselectAllPressed:(UIButton*)button {
int id = button.tag;
[SVProgressHUD showWithStatus:@"Updating" maskType:SVProgressHUDMaskTypeGradient];
[self displaySelected]; // removes current view so you can load hud will not be behind it
if (id == 1) {
[self selectAllD];
} else if (id == 2) {
[self deselectAllD];
} else if (id == 3) {
[self selectAllI];
} else if (id == 4) {
[self deselectAllI];
}
}
ご覧のとおり、ボタンが押されたときにこのメソッドが呼び出されると、他のメソッドが呼び出される前に、displaySelected メソッドが必要なことを実行したいと思いますか?
現在、これをデバッグするとどうなるかというと、displaySelected メソッドが呼び出され、スレッド ウォークスルーが呼び出され、if ステートメントに進み、if ステートメントのメソッドが終了した後、displaySelected の変更が行われます...とても奇妙です。
アップデート
これは私が呼び出しているメソッドです。ビューが nil かどうかをチェックする if ステートメントがあり、それ以外の場合はアンロードします。私がビューにいるコードの時点でロードされているので、selectDeselectAllPressedから呼び出すと、ビューを閉じるメソッドの一部にelse ifが入力されます。私はデバッグし、スレッドがこの時点に入るのを見ました
- (void) displaySelected {
if (allBackGroundView == nil) {
// load view
CGFloat fullHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat fullWidth = [UIScreen mainScreen].bounds.size.width;
// draw background
background = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, fullHeight, fullWidth)];
background.backgroundColor = [UIColor blackColor];
background.alpha = 0.6;
[self.view addSubview:background];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displaySelectedI)];
gestureRecognizer.cancelsTouchesInView = NO;
[background addGestureRecognizer:gestureRecognizer];
allBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(762.0, 43.0, 250.0, 220.0)];
allBackGroundView.backgroundColor = [UIColor lightGrayColor];
allBackGroundView.layer.borderWidth = 0.5;
allBackGroundView.layer.borderColor = [UIColor darkGrayColor].CGColor;
[self.view addSubview:allBackGroundView];
// set labeltitles
selecteAllDFitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 18.0, 200.0, 30.0)];
selecteAllDFitLabel.backgroundColor = [UIColor clearColor];
selecteAllDFitLabel.font = [UIFont boldSystemFontOfSize:16];
selecteAllDFitLabel.textColor = [UIColor whiteColor];
selecteAllDFitLabel.text = @"Select all Dfit:";
[allBackGroundView addSubview:selecteAllDFitLabel];
deselecteAllDFitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 65.0, 200.0, 30.0)];
deselecteAllDFitLabel.backgroundColor = [UIColor clearColor];
deselecteAllDFitLabel.font = [UIFont boldSystemFontOfSize:16];
deselecteAllDFitLabel.textColor = [UIColor whiteColor];
deselecteAllDFitLabel.text = @"Deselect all Dfit:";
[allBackGroundView addSubview:deselecteAllDFitLabel];
selecteAllILabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 120.0, 200.0, 30.0)];
selecteAllILabel.backgroundColor = [UIColor clearColor];
selecteAllILabel.font = [UIFont boldSystemFontOfSize:16];
selecteAllILabel.textColor = [UIColor whiteColor];
selecteAllILabel.text = @"Select all I:";
[allBackGroundView addSubview:selecteAllILabel];
deselecteAllILabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 170.0, 200.0, 30.0)];
deselecteAllILabel.backgroundColor = [UIColor clearColor];
deselecteAllILabel.font = [UIFont boldSystemFontOfSize:16];
deselecteAllILabel.textColor = [UIColor whiteColor];
deselecteAllILabel.text = @"Deselect all I:";
[allBackGroundView addSubview:deselecteAllILabel];
UIImage* okImage = [UIImage imageNamed:@"OK.png"];
UIImage* noImage = [UIImage imageNamed:@"No.png"];
selecteAllDFitButton =[UIButton buttonWithType:UIButtonTypeCustom];
selecteAllDFitButton.tag = 1; // so I know what action to perform when i call selectDeselectAllPressed
[selecteAllDFitButton addTarget:self
action:@selector(selectDeselectAllPressed:)
forControlEvents:UIControlEventTouchUpInside];
selecteAllDFitButton.frame = CGRectMake(200.0, 12.0, 40.0, 40.0);
[selecteAllDFitButton setImage:okImage forState:UIControlStateNormal];
[allBackGroundView addSubview:selecteAllDFitButton];
deselecteAllDFitButton =[UIButton buttonWithType:UIButtonTypeCustom];
deselecteAllDFitButton.tag = 2;
[deselecteAllDFitButton addTarget:self
action:@selector(selectDeselectAllPressed:)
forControlEvents:UIControlEventTouchUpInside];
deselecteAllDFitButton.frame = CGRectMake(200.0, 62.0, 40.0, 40.0);
[deselecteAllDFitButton setImage:noImage forState:UIControlStateNormal];
[allBackGroundView addSubview:deselecteAllDFitButton];
selecteAllIButton =[UIButton buttonWithType:UIButtonTypeCustom];
selecteAllIButton.tag = 3;
[selecteAllIButton addTarget:self
action:@selector(selectDeselectAllPressed:)
forControlEvents:UIControlEventTouchUpInside];
selecteAllIButton.frame = CGRectMake(200.0, 112.0, 40.0, 40.0);
[selecteAllIButton setImage:okImage forState:UIControlStateNormal];
[allBackGroundView addSubview:selecteAllIButton];
deselecteAllIButton =[UIButton buttonWithType:UIButtonTypeCustom];
deselecteAllIButton.tag = 4;
[deselecteAllIButton addTarget:self
action:@selector(selectDeselectAllPressed:)
forControlEvents:UIControlEventTouchUpInside];
deselecteAllIButton.frame = CGRectMake(200.0, 162.0, 40.0, 40.0);
[deselecteAllIButton setImage:noImage forState:UIControlStateNormal];
[allBackGroundView addSubview:deselecteAllIButton];
}
else {
[allBackGroundView removeFromSuperview];
[background removeFromSuperview];
allBackGroundView = nil;
background = nil;
}
}