我正在构建一个简单的应用程序。带有 TableView 和嵌入式导航 Controller 的 1 View Controller 中的项目列表。当您选择一行时,它会将您带到详细信息屏幕(没问题)。
从 ListView 推送到列表项
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "ListItemDetailsVC", sender: nil)
}
从列表项弹出回到 ListView
@IBAction func backToInboxTapped(_ sender: Any) {
navigationController?.popToRootViewController(animated: true)
}
这很好用!
我的问题是我有另一个 View Controller (添加项),它在单击添加按钮时以模态方式显示。这个想法是,当它保存时,它会将您带到列表详细信息 vc。
@IBAction func saveItem(_ sender: Any) {
performSegue(withIdentifier: "DetailsFromAdd", sender: nil)
}
从添加新 Controller 打开详细信息 View Controller 工作正常,但一旦我打开详细信息 View ,我希望能够返回到 rootViewController。该按钮不再起作用
最佳答案
在您的情况下,您不需要使用 segue。你必须弄清楚一些概念。
如果你已经从 modally presented vc 推送或显示 View Controller ,你不能 popToRootViewController 或 VC!!
现在,如果你想实现这一点,那么你必须做出一些我在下面要提到的改变:
在您的add item VC 中获取一个全局变量或属性(objective c 概念)。现在,当你从 lust VC 开始 add item VC 时,将这个全局变量或属性设置为 self 之类的,
AddListItemVC *advc = [self.storyboard instantiateViewControllerWithIdentifier:@"addListItem"]; // addListItem is storyboard id for viewcontroller
[self presentViewController:advc animated:NO completion:^{
advc.vc = self; // here vc is the propery of type `UIVIewController` declare in AddListItemVC
}];
现在你从 add list VC 转到 details VC 的代码应该是这样的,
DetailListViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"detailViewScreen"]; // detailViewScreen is storyboard id which you can set from identity inspector
[self dismissViewControllerAnimated:NO completion:^{
[self.vc.navigationController pushViewController:dvc animated:YES]; // here self.vc is global variable or property that contains reference of first VC (i.e. list view controller)
}];
在这种情况下不需要使用performsegue。您可以使用 performsegue 直接从 firstvc 进入 detailvc 我的意思是从 list vc。
希望您能理解概念,由于时间有限,我已经编写了 objective-c 代码段!!希望您可以轻松转换为 swift!!
关于ios - 从添加屏幕发送时 popToRootViewController 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40485144/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的