[英]How Do I Make A Button Get An Alert View To Pop Up When Pressed And Go Back To The Main View Controller?
NOTE: Apologies in advance for my lack of being able to explain easily, as well as being only half a semester of coding knowledge, high school 注意: 预先道歉是因为我缺乏能够轻松解释的能力,并且只有半个学期的编码知识,高中
So, recently I have had a project I have to do for a class, and it's one of those basic "Choose-Your-Own-Adventure" (CYOA) type of stories. 因此,最近我有一个班级要做的项目,它是那些基本的“自主选择冒险”(CYOA)类型的故事之一。 However, as of now, I only have the navigation controller. 但是,到目前为止,我只有导航控制器。 One of the things I am having trouble with is getting the button at the end to pop up an alert view when pressed, so to say something like "Story finished! Go back to start!" 我遇到的麻烦之一是,按下按钮时会获得最后的按钮以弹出警报视图,因此可以说诸如“故事完成!返回开始!”之类的内容。 and then of course the "Okay" button part on the alert view. 然后当然是警报视图中的“确定”按钮部分。
I know how to make an alert view, but only popping up because of a condition. 我知道如何制作警报视图,但由于情况而仅会弹出。 We had a project called Tic-Tac-Toe, and when one wins, an alert view pops up. 我们有一个名为“井字游戏”的项目,当一个项目获胜时,会弹出一个警报视图。 What I want to do with my CYOA app is make it so when you press the "Go Back To Start" button an alert view will pop up, as well as take you back to the initial view controller. 我要用CYOA应用程序进行的操作就是这样,当您按下“ Go Back To Start”按钮时,将弹出一个警报视图,并将您带回到初始视图控制器。 The navigation controller will also be available in the app, so I do not want to take that out, however, having a "Go Back To Start" button at the end of each story line or path, will allow the user to not have to go back through the previous story line that they just came from, and rather save them a bit of taps. 导航控制器也将在该应用程序中可用,因此我不想删除它,但是,在每个故事行或路径的末尾都有一个“ Go Back To Start”按钮,将使用户不必返回到他们刚来自的上一个故事情节,而是节省一些水龙头。
There (pictured above) is the code for one of the ends. 上面的代码是其中之一的代码。 However, I know I have messed up in making this code work. 但是,我知道我搞砸了使此代码正常工作。
The goBackOnTapped is referring to the "Go Back To Start" button. goBackOnTapped指的是“返回开始”按钮。
I am also willing to put up a copy of the file on an external site, of what I have so far if you would like to see otherwise into the code. 我也愿意将文件的副本放到外部站点上,如果您希望在代码中看到其他内容,则可以复制到此为止。
You can find the code here: Link to file via Canvas 您可以在此处找到代码: 通过Canvas链接到文件
Don't have enough rep to put a comment. 没有足够的代表发表评论。 I think what you need is this: 我认为您需要的是:
self.navigationController?.popToRootViewControllerAnimated(true);
Saves you the unwanted taps. 为您节省不必要的水龙头。
There's a method you can use that will instantiate the initial view controller. 您可以使用一种方法来实例化初始视图控制器。
let initialView = storyboard.instantiateInitialViewController()
self.presentViewController(initialView, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.