我收到以下错误。
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()
尝试了以下解决方案,但对我不起作用Attempting to load the view of a view controller while it is deallocating... UISearchController
链接中提供了一个演示项目。
代码如下所示,可以从简称time at下载.
import UIKit
class DetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,UISearchResultsUpdating,UISearchBarDelegate {
@IBOutlet weak var basicTable: UITableView!
var tblSearchController:UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tblSearchController = UISearchController(searchResultsController: nil)
self.basicTable.tableHeaderView=self.tblSearchController.searchBar
// self.tblSearchController.edgesForExtendedLayout = (UIRectEdge.Top )
// self.tblSearchController.extendedLayoutIncludesOpaqueBars = true
self.tblSearchController.searchResultsUpdater = self
self.tblSearchController.searchBar.delegate = self
self.tblSearchController.searchBar.sizeToFit()
// self.tblSearchController.searchBar.frame=CGRectMake(0, 0, self.basicTable.frame.size.width, 44.0)
self.tblSearchController.hidesNavigationBarDuringPresentation=true
self.tblSearchController.dimsBackgroundDuringPresentation=true
self.definesPresentationContext=true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let aCell:UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("123")
return aCell
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
print("Begin Update = \(NSStringFromCGRect(self.tblSearchController.searchBar.frame)) \(self.tblSearchController.view.frame) ")
}
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
print("Begin= \(NSStringFromCGRect(searchBar.frame))")
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
print("End=\(NSStringFromCGRect(searchBar.frame))")
}
}
最佳答案
问题是 UISearchController 中的一个错误,它试图在它的 dealloc 方法中加载它的 View 。可能它调用了 self.view 而作者忘记了 self.view 导致加载 View 。如果 UISearchController 已创建但尚未使用,则它不会加载其 View ,就会出现此问题。在您的示例项目中,如果您点击 SearchBar,则不会出现警告。
解决方案是强制它加载它的 View 。在您的代码中,您可以在两个地方执行此操作:viewDidLoad() 或 deinit。使用建议的行之一(loadViewIfNeeded() 或 _ = .view)而不是两者。如果您只使用 iOS 9,那么最好是在 deinit 中使用 loadViewIfNeeded 代码。如果您支持 iOS 8,则如图所示手动加载 View 。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tblSearchController = UISearchController(searchResultsController: nil)
// etc. setup tblSearchController
self.tblSearchController.loadViewIfNeeded() // iOS 9
let _ = self.tblSearchController.view // iOS 8
}
deinit {
self.tblSearchController.loadViewIfNeeded() // iOS 9
let _ = self.tblSearchController.view // iOS 8
}
关于ios - UISearchController - 警告尝试加载 View Controller 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32675001/
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c