我正在尝试从一个视图控制器执行切换到另一个视图控制器,以便可以传递数据。我正在将文本从文本字段传递到标签。另外,我正在尝试将文本字段中的数据写入Firebase数据库。它不允许我在执行segue的同时写入数据。为什么会这样,我又怎么能同时做这两个呢?
我已经在两个视图控制器之间创建了一个显示标识为“ nextTransition”的节目。当我在添加数据库代码之前按下按钮时,segue工作。一旦添加了要写入数据库的代码,便出现了无法写入数据库的问题。它试图使用func来执行segue,但是它并没有改变任何东西。
public void run(String[] args) {
if (args.length < 2) {
System.out.println("Not enough parameters");
System.out.println("Program arguments:\n<image_name> <template_name> [<mask_name>]");
System.exit(-1);
}
img = Imgcodecs.imread(args[0], Imgcodecs.IMREAD_COLOR);
templ = Imgcodecs.imread(args[1], Imgcodecs.IMREAD_COLOR);
if (args.length > 2) {
use_mask = true;
mask = Imgcodecs.imread(args[2], Imgcodecs.IMREAD_COLOR);
}
if (img.empty() || templ.empty() || (use_mask && mask.empty())) {
System.out.println("Can't read one of the images");
System.exit(-1);
}
matchingMethod();
createJFrame();
}
下面是我为show segue“ nextTransition”创建的功能。
public class MatchTemplateDemo {
public static void main(String[] args) {
// load the native OpenCV library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// run code
new MatchTemplateDemoRun().run(args);
}
}
我希望它能在Firebase数据库中创建显示titleTextField.text的内容,但是它什么也没做。
答案 0 :(得分:1)
写入firebase是一个异步功能。当您选择到新的VC时,它将在完成写入之前关闭与Firebase的连接。在setValue方法的完成处理程序中选择到新的VC。
ref?.child("Title").childByAutoId().setValue(`YourValue`) { (error, ref) in
if error == nil {
self.performNextTransitionSegue()
} else {
print("error")
}
}
答案 1 :(得分:0)
如我所见,您在此行中犯了一个错误:
ref?.child("Title").childByAutoId().setValue("titleTextField.text")
因为
titleTextField.text
一定不能是字符串,我的意思是它不需要用引号引起来。
之后请检查
titleTextField.text != ""
正在获得一些价值,这可能避免您进行测试,可以使用调试器进行检查。
如果线路正在运行,请检查您的segue名称是否正确。