简体   繁体   English

如何在按下按钮时使按钮弹出警报视图并返回主视图控制器?

[英]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”按钮,将使用户不​​必返回到他们刚来自的上一个故事情节,而是节省一些水龙头。

Code for my project 我的项目的代码

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.

相关问题 按下后退按钮,当我将视图控制器从堆栈中弹出时,将丢失我的自定义UIToolBar - Back button pressed, losing my custom UIToolBar when i pop the view controller off the stack 在Swift 3中按下按钮时如何转到另一个视图控制器 - How to go to another view controller when button is pressed in swift 3 在Xcode中按下按钮时如何去相同的视图控制器? - how to go same view controller when button pressed in Xcode? 当导航栏的内置后退按钮被按下时弹出到根视图控制器 - Pop to the root view controller when the navigation bar's built in back button is pressed 如何使按钮返回到指定的视图控制器 - How to make button go back to specified view controller 如何使用自定义警报弹出视图切换警报弹出视图? - How do I switch the Alert Pop-Up View with a custom Alert popup View? 在导航控制器中按下“后退”按钮时,是否可能不取消分配视图控制器? - is it possible to not dealloc a view controller when the back button is pressed in a navigation controller? 如何让关闭等待玩家按下不同视图控制器中的按钮? - How do I make a closure wait until the player pressed a button in a different view controller? 用户点击注销按钮时如何弹出所有视图并返回登录视图 - How to pop all view and go back to login view when user tap logout button 如何在视图控制器中创建后退按钮以转到父视图控制器 - How to create a back button in a view controller to go to parent view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM