我正在尝试重新加载我的 TableView,但我收到此异常“由于未捕获的异常‘NSInternalInconsistencyException’而终止应用程序,原因:‘尝试从第 1 节中删除第 3 行,该节仅包含更新前的 0 行’”。
下面是我的代码:-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if statusTableView == tableView {
return ModelAssessStatus.sharedInstance.arrType.count
}
else {
if !sections[section].expanded {
return 0
}
else {
return sections[section].names.count
}
//return sections[section].names.count
/*if sections[section].expanded == true {
return sections[section].names.count
}
else {
return 0
}*/
}
}.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var expandableCategoryCell = tableView.dequeueReusableCell(withIdentifier: "ExpandableCategoryCell") as? ExpandableCategoryCell
if expandableCategoryCell == nil {
var nib:Array = Bundle.main.loadNibNamed("ExpandableCategoryCell", owner: self, options: nil)!
expandableCategoryCell = nib[0] as? ExpandableCategoryCell
}
expandableCategoryCell?.selectionStyle = .none
expandableCategoryCell?.labelName.text = sections[indexPath.section].names[indexPath.row]
return expandableCategoryCell!
//return UITableViewCell()
}.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if tableView == self.expandableTableView {
return 60
}
return 0
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if tableView == self.expandableTableView {
return 0
}
return 0
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if tableView == expandableTableView {
let cell = self.expandableTableView.dequeueReusableHeaderFooterView(withIdentifier: "ExpandableHeaderView")
let header = cell as! ExpandableHeaderView
header.customInit(title: sections[section].categoryType, section: section, delegate: self, isSelected: sections[section].fullSelected)
if sections[section].expanded {
header.imgArrow?.image = UIImage(named : "down_Arow")//.transform = (header.imgArrow?.transform.rotated(by: CGFloat(Double.pi)))!
}
else {
header.imgArrow?.image = UIImage(named : "error")
}
return cell
}
else {
return UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
}
}
//Height For Raw at indexPath
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if statusTableView == tableView {
return 50
}
else {
if (sections[indexPath.section].expanded) {
return 60
}
else {
return 0
}
}
}
}
extension PeerCategoryStatusVC : expandableHeaderViewDelegate {
func toggleSections(header: ExpandableHeaderView, section: Int) {
sections[section].expanded = !sections[section].expanded
//expandableTableView.reloadData()
expandableTableView.beginUpdates()
for index in 0..<sections[section].names.count {
expandableTableView.reloadRows(at: [IndexPath(row : index, section : section)], with: .automatic)
}
expandableTableView.endUpdates()
//self.view.layoutIfNeeded()
}
}.
此处开始更新并结束更新 TableView。 我正在尝试重新加载 tableView 但不知道为什么会出现异常。
如果我将保留相同的行数,那么就会出现约束问题。
有什么要补充的吗?
最佳答案
我只是修复了同样的异常。这主要是因为你调用 reloadRows(at: with:) 的 indexPath(s) 的 row 大于总行数。
关于ios - 由于未捕获的异常而终止应用程序,原因 : 'attempt to delete row 3 from section 1 which only contains 0 rows before the update' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46506789/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',