Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS popToRootViewControllerAnimated不在委托方法上工作_Ios_Swift_Asynchronous - Fatal编程技术网

iOS popToRootViewControllerAnimated不在委托方法上工作

iOS popToRootViewControllerAnimated不在委托方法上工作,ios,swift,asynchronous,Ios,Swift,Asynchronous,我已经实现了一个自定义委托方法,如果一些数据来自服务器,它应该弹出根视图控制器。 通过单击子控制器中的后退按钮,第一种方法back()检查文本字段中是否有任何更改,如果有一些更改,则显示UIActionSheet 1. func back() { if modified { let actionSheet = UIActionSheet(title: NSLocalizedString("SAVESETTINGS", comment: "Settings

我已经实现了一个自定义委托方法,如果一些数据来自服务器,它应该弹出根视图控制器。 通过单击子控制器中的后退按钮,第一种方法
back()
检查文本字段中是否有任何更改,如果有一些更改,则显示UIActionSheet

1.

func back() {
        if modified {
            let actionSheet = UIActionSheet(title: NSLocalizedString("SAVESETTINGS", comment: "Settings were changed. Do you want to save them?"), delegate: self, cancelButtonTitle: "No", destructiveButtonTitle: "Yes")
            actionSheet.actionSheetStyle = .Default
            actionSheet.showInView(self.view)
        }
        else {
            self.navigationController?.popToRootViewControllerAnimated(true)
        }
    }
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex == 0 {
        self.socket.send(someData, tag: someTag)
    }
    else {
       self.modified = false
       self.navigationController?.popToRootViewControllerAnimated(true)
    }     
}
func ackReceived(tag: Int32) {
    if tag == someTag {
        self.navigationController?.popToRootViewControllerAnimated(true)
    }
}
ActionSheet委托方法发送数据,控制器正在等待答案
2.

func back() {
        if modified {
            let actionSheet = UIActionSheet(title: NSLocalizedString("SAVESETTINGS", comment: "Settings were changed. Do you want to save them?"), delegate: self, cancelButtonTitle: "No", destructiveButtonTitle: "Yes")
            actionSheet.actionSheetStyle = .Default
            actionSheet.showInView(self.view)
        }
        else {
            self.navigationController?.popToRootViewControllerAnimated(true)
        }
    }
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex == 0 {
        self.socket.send(someData, tag: someTag)
    }
    else {
       self.modified = false
       self.navigationController?.popToRootViewControllerAnimated(true)
    }     
}
func ackReceived(tag: Int32) {
    if tag == someTag {
        self.navigationController?.popToRootViewControllerAnimated(true)
    }
}
委托方法检查正确答案是否在此处,并应弹出根视图控制器

3.

func back() {
        if modified {
            let actionSheet = UIActionSheet(title: NSLocalizedString("SAVESETTINGS", comment: "Settings were changed. Do you want to save them?"), delegate: self, cancelButtonTitle: "No", destructiveButtonTitle: "Yes")
            actionSheet.actionSheetStyle = .Default
            actionSheet.showInView(self.view)
        }
        else {
            self.navigationController?.popToRootViewControllerAnimated(true)
        }
    }
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex == 0 {
        self.socket.send(someData, tag: someTag)
    }
    else {
       self.modified = false
       self.navigationController?.popToRootViewControllerAnimated(true)
    }     
}
func ackReceived(tag: Int32) {
    if tag == someTag {
        self.navigationController?.popToRootViewControllerAnimated(true)
    }
}
如果没有更改,或者在UIActionSheet中按了第二个按钮,但它在3d方法中不工作,则根视图控制器将在第1个和第2个方法中弹出

所有方法都被调用。我最终以失败告终

self.navigationController?.popToRootViewControllerAnimated(true)
我还检查了调试器,导航控制器不是
nil

我希望你能帮我解决这个问题。
非常感谢。

谢谢Wain的提示,我发现了问题所在<未在主队列中调用code>func ackReceived(标记:Int32){}。 UI as UIKit方法不是线程安全的,应该在主队列中调用

func ackReceived(tag: Int32) {
    if tag == someTag {
        dispatch_async(dispatch_get_main_queue(), {
                self.navigationController?.popToRootViewControllerAnimated(true)
                return
            })
    }
}
是调用UI方法的正确方法


非常感谢您的帮助。

因为您的导航为零,所以无法工作。例如,您可以通过print(“mainicontaped:+String(self.navigationController))

第三个例子中的self是什么?添加一个
NSLog(@“%@”,self)
这三种方法在同一个控制器中。我不管它们在哪里,我想知道你在日志中看到了什么。(抱歉,这不是故意的)。日志显示的是我所在的同一个控制器。您是否将NSLog(@“%@”,self)添加到每个方法的开头?如果是,请在此处复制粘贴输出。为什么你要努力避免发布控制台日志?