我试图直接从其兄弟窗口显示一个ViewController,树看起来像这样:CalibrationVC< --- MainVC --->设置VC。 MainVC呈现另外两个模态和过流背景。现在我要做的是点击SettingsVC中的一个按钮,这将打开特定设备的CalibrationVC。我已经设法使用unwind segues和来自SettingsVC的委托,它看起来像这样:
- (void)showViewForDeviceCalibration
{
[self performSegueWithIdentifier:@"showCalibrationViewFromSettings" sender:nil];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showCalibrationViewFromSettings"])
{
[_delegate calibrateDevice:deviceToConfigure];
}
}
委托实施:
-(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);
}
准备segue方法:
- (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];
}
这很有效,但是有更好的方法吗?我真的很关心委托实现,因为它只使用一个单独的线程等待片刻,然后再次使用主线程。我不得不这样做,因为没有它,CalibrationVC似乎不会说MainVC已经出现了。总而言之,是否有更好,更优/正确的方法来做到这一点?
答案 0 :(得分:1)
如果你不需要特别需要解开segues,你可以这样做:
设置VC:
- (void)showViewForDeviceCalibration
{
[_delegate calibrateDevice:deviceToConfigure];
}
代表:
-(void)calibrateDevice:(Device *)device
{
[self dismissViewControllerAnimated:YES completion:^{
[self performSegueWithIdentifier:@"showCalibrationViewForDeviceFromSettings" sender:nil];
}];
}