Vote count:
0
I am trying to show a ViewController directly from its sibling window, the tree looks kinds like this: CalibrationVC<--- MainVC ---> Settings VC. The MainVC presents the other two modally, and over current context. Now what I want to do is click a button in SettingsVC, that would open the CalibrationVC for a specific device. I have managed to do so using unwind segues and a delegate from the SettingsVC, and it looks like this:
- (void)showViewForDeviceCalibration
{
[self performSegueWithIdentifier:@"showCalibrationViewFromSettings" sender:nil];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showCalibrationViewFromSettings"])
{
[_delegate calibrateDevice:deviceToConfigure];
}
}
The delegate implementation:
-(void)calibrateDevice:(Device *)device
{
dispatch_block_t autoinitService =
^{
deviceToCalibrateFromSettings = device;
[NSThread sleepForTimeInterval:0.2];
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"showCalibrationViewForDeviceFromSettings" sender:nil];
});
};
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), autoinitService);
}
And the prepare for segue method:
- (void)prepareForSegue: (UIStoryboardSegue *)segue sender:(id) sender
{
if ([segue.identifier isEqualToString:@"showCalibrationViewForDeviceFromSettings"])
{
CalibrationViewController *destinationController = (CalibrationViewController*)segue.destinationViewController;
NSArray *devicesToCalibrate = [NSArray arrayWithObject:deviceToCalibrateFromSettings];
[destinationController setDevicesToCalibrate: devicesToCalibrate];
}
This works well, but is there a better way to do that? I am really concerned about the delegate implementation because it uses a separate thread only to wait for a moment and then use the main thread again. I had to do this because without it the CalibrationVC would not appear saying that the MainVC is already presenting. So to sum thing up, is there a better, more optimal/proper way to do this?
Showing a view controller from a parallel window (with the same parent)
Aucun commentaire:
Enregistrer un commentaire