草庐IT

iphone - iOS 7 错误警告 : Attempt to dismiss from view controller <UINavigationController: 0x1568db40> while a presentation or dismiss is in progress

coder 2023-09-26 原文

我在 iOS 7 中遇到的问题在 iOS 6 中没有出现。

我有一个导航 Controller 显示另一个导航 Controller 来添加员工。第二个 Controller 以模态方式呈现。当我使用“取消”或“完成”按钮关闭第二个 Controller 时,出现错误。这是错误:

QuickSchedule[880:60b] Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

我正在使用 unwind segue 并使用以下相关代码从第一个 Controller 中解雇。

这是在 ScheduleViewController.m(我的主 Controller 窗口)

- (IBAction)done:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"DoneEditing"]) {
        [[MyManager sharedManager] saveChanges];
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

“完成”按钮的连接检查器中的连接很简单 “行动 -> [放松完成:]”

在升级到 Xcode 5 之前我没有任何错误。这一切都是在将 Xcode 和我的 Storyboard升级到 iOS 7 之后开始的。

我在我的应用程序的不同位置遇到了同样的错误,但同样,它与模态呈现的 View Controller 有关。

我以模态方式从 EmployeeViewController 转到 AddEmployeeViewController。当我从 AddEmployeeViewController 返回时,我再次收到错误。

EmployeeViewController.m

- (IBAction)done:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"ReturnInput"]) {
        AddEmployeeViewController *addController = [segue sourceViewController];
        if (addController.employee) {
            [[MyManager sharedManager] saveChanges];
            [[self tableView] reloadData];
        }
        if (![self.presentedViewController isBeingDismissed]) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
}

- (IBAction)cancel:(UIStoryboardSegue *)segue
{
    if ([[segue identifier] isEqualToString:@"CancelInput"]) {
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

这里是AddEmployeeViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"ReturnInput"]) {
        if ([self.firstNameField.text length] || [self.lastNameField.text length]) {

            Employee *newEmployee = [[MyManager sharedManager] createEmployeeWithFirstName:self.firstNameField.text andLastName:self.lastNameField.text];
            [[MyManager sharedManager] addEmployeeToList:newEmployee];
            self.employee = newEmployee;
        }
    }
}

我还在学习,我在网上找了好几个小时都找不到这个问题的答案。我试过将“保存代码”放在完成 block 中。我把它放回去并尝试在完成 block 参数中使用 nil 而不是 NULL。如您所见,我在完成 block 参数的一个位置上有 nil,在另一个位置上有 NULL。无论如何,错误不断出现。

就功能而言一切正常,我只是将此错误记录到控制台。非常感谢任何帮助。

注意: 使用常规推送导航 Controller 时,我不会收到此错误。这只会在关闭模态呈现的 View Controller 时发生。

最佳答案

令我惊讶的是,您在以前版本的 Xcode 中没有看到同样的问题,因为我认为您的问题是在“完成”方法中调用 dismissViewControllerAnimated:completion:。这应该也是 iOS 6 中的一个问题。 unwind segue 为您完成解雇,因此您不应该自己调用此方法。尝试将其注释掉,看看是否能解决问题。

关于iphone - iOS 7 错误警告 : Attempt to dismiss from view controller <UINavigationController: 0x1568db40> while a presentation or dismiss is in progress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18901079/

有关iphone - iOS 7 错误警告 : Attempt to dismiss from view controller <UINavigationController: 0x1568db40> while a presentation or dismiss is in progress的更多相关文章

随机推荐