jjzjj

swift - TableView ReloadSection 崩溃了吗?

coder 2023-09-16 原文

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试删除第 100 节,但更新前只有 7 个节” *** 首先抛出调用栈:

我正在尝试制作可折叠的 TableView WithAnimation。从 Header 中点击 View ,它将调用切换部分方法。Ima 的工作基于它是否被选中或不是 bool 值。

class ExploreLocallyVc: UIViewController {
var headerViewMain = HeaderView()
@IBOutlet weak var tableView: UITableView?
var ArrayOfCollapsable : [Int:Bool]? = [:]
var prevIousSelection : Int? = 100
override func viewDidLoad() {
    super.viewDidLoad()
    
    tableView?.estimatedRowHeight = 80
    tableView?.rowHeight = UITableViewAutomaticDimension
    tableView?.sectionHeaderHeight = 60
    tableView?.separatorStyle = .none
   
}
}

extension ExploreLocallyVc:UITableViewDelegate,UITableViewDataSource
{
    func numberOfSections(in tableView: UITableView) -> Int
{
    return 7
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    if (ArrayOfCollapsable?[section] == true) {
        print("yes")
       return 4
    }
    else
    {
    print("No")
       return 0
    }
    }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCell(withIdentifier: "q", for: indexPath)
     cell.textLabel?.text = "\(indexPath.row)"
    return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
    headerViewMain = (Bundle.main.loadNibNamed("HeaderView", owner: self, options: nil)![0] as? HeaderView)!
    headerViewMain.titleLabel?.text = "\(section)"
    if (ArrayOfCollapsable?[section] == true) {
       headerViewMain.arrowLabel?.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
    }
    headerViewMain.section = section
    headerViewMain.delegate = self
  
    return headerViewMain
}
}

extension ExploreLocallyVc:HeaderViewDelegate
{
func toggleSection(header: HeaderView, section: Int)
{
    
    if (ArrayOfCollapsable?[section] == true) {
        print("yes")
       ArrayOfCollapsable?[section] = false
    }
    else
    {
        print("No")
        ArrayOfCollapsable?[section] = true
        ArrayOfCollapsable?.updateValue(false, forKey: prevIousSelection!)
    }
    tableView?.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
    prevIousSelection = section
    print(ArrayOfCollapsable!)
}

最佳答案

我先重新加载了上一节,然后重新加载了更改后的部分,如下所示

 func toggleSection(header: HeaderView, section: Int)
{

    if (ArrayOfCollapsable?[section] == true) {
        print("yes")
       ArrayOfCollapsable?[section] = false
    }
    else
    {
    print("No")
    ArrayOfCollapsable?.updateValue(false, forKey: prevIousSelection!)
    if (tableView?.numberOfSections)! >= prevIousSelection!{
        tableView?.reloadSections(NSIndexSet(index: prevIousSelection!) as IndexSet, with: .automatic)
    }
    ArrayOfCollapsable?[section] = true
    }
    tableView?.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
    prevIousSelection = section
    print(ArrayOfCollapsable!)
}

关于swift - TableView ReloadSection 崩溃了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48474338/

有关swift - TableView ReloadSection 崩溃了吗?的更多相关文章

  1. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  2. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  3. ruby - 在多个线程中引用类方法会导致自动加载循环依赖崩溃 - 2

    代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,

  4. ruby - 执行过期异常使 Ruby 线程崩溃,但处理了 Timeout::Error - 2

    任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb

  5. ruby - vim 使用 AutoComplPop 插件崩溃 - 2

    我使用vim编辑ruby​​文件,但是当我输入“.”时它崩溃了。我发现它是由AutoComplPop插件引起的。我该怎么办? 最佳答案 我找到了一种使用autocomplpop和filetype=ruby来防止vim崩溃的方法。将以下行放入您的.vimrcletg:acp_behaviorRubyOmniMethodLength=-1这将防止在您键入“.”时触发autocomplpop。(期间)这不是解决办法。(我不是vim插件程序员)祝你好运! 关于ruby-vim使用AutoComp

  6. ruby-on-rails - 自动加载路径和嵌套服务类在 Ruby 中崩溃 - 2

    我在Rails5项目的app/services文件夹下有多个加载/需要类的问题,我开始放弃这个问题。首先要明确的是,services/是我在整个项目中使用的简单PORO类,用于从Controller、模型等中抽象出大部分业务逻辑。树看起来像这样app/services/my_service/base.rbfunny_name.rbmy_service.rbmodels/funny_name.rb失败#1首先,当我尝试使用MyService.const_get('FunnyName')时,它从我的模型目录中获取了FunnyName。当我直接执行MyService::FunnyName时,

  7. ruby - instance_eval 的 block 参数 - 记录了吗?目的? - 2

    刚刚意识到instance_eval产生self作为关联block的参数(除了1.9.2版本中的错误:http://www.ruby-forum.com/topic/189422)1.9.3p194:003>classC;end1.9.3p194:004>C.new.instance_eval{|*a|a}=>[#]1.9.3p194:005>这是否在某处记录/规范?看着ruby-doc:BasicObject,看不到提到的任何block参数。除了一些纯粹的历史原因之外,是否还有其他原因明确地传递它,而它自己总是被定义?我被这个击中的方式是:l=lambda{}myobj.instan

  8. ruby - unicorn 与 Ruby 2.4.1 导致奇怪的崩溃 - 2

    我正在从Ruby2.3.1升级到Ruby2.4.1,这样做之后,Unicorn似乎与新版本不兼容。我收到以下错误。我正在使用Unicorn5.1.0并尝试过Unicorn5.3.1无济于事。我是否需要使用不同的库而不是XCode工具进行编译?我在使用foremanstart和Procfile启动服务器后立即收到错误:webpack:bin/webpack-dev-servergulp:gulpredis:./scripts/start_redis_server.shsidekiq:bundleexecsidekiq-Cconfig/sidekiq.ymlannotations_serv

  9. ruby-on-rails - Rails 3.2.13 与 Rails 4.0.1 - 改变了吗?方法变了? - 2

    我最近注意到ActiveRecord对象上的方法changed?在Rails3.2.13和Rails4.0.1之间发生了变化。问题在于连接到数据库中整数字段的字段。假设我的模型Model带有number整数字段:#Rails3.2.13m=Model.lastm.number#=>5m.number='5hello'm.number#=>5m.number_changed?#=>truem.changed?#=>truem.changes#=>{:number=>[5,5]}#Rails4.0.1m=Model.lastm.number#=>5m.number='5hello'm.nu

  10. ruby - 网站不再需要本地数据库了吗? - 2

    Ifthere'sabetterplacetoaskthis,pleaseletmeknow.每次我建立一个新的网站/博客/购物车/等等,我都会不断尝试做以下事情:将常用功能提取到可重用代码中(主要是Rubygems和jQuery插件)如果可能,将该gem转换成一个小型服务,这样我就不必为所涉及的对象处理数据库(服务,我指的是精简的东西,通常使用SinatraWebFramework和一些核心模型构建).我的假设是,如果我可以消除对本地数据库的依赖,从长远来看,这将使它变得更容易和更具可扩展性(在可重用性和可管理性方面可扩展,不一定是数据库/性能)。我不确定这是好假设还是坏假设。你怎么

随机推荐