菜鸟教程小白 发表于 2022-12-11 18:06:39

ios - 如何扩展单个特定部分?


                                            <p><p>我使用了名为“ExpandableTableView”的第三方可扩展表格 View ,当我想在我的 View 中使用自定义按钮扩展特定的单个部分时。我的代码片段是:</p>

<pre><code>UIView *view=Gesture.view;
    isFirsTime=NO;
    //NSLog(@&#34;%ld&#34;,(long)view.tag);
    for (int h=0; h&lt;dicAll.count; h++)
    {
      NSString *strRegisterId=[[valueForKey:@&#34;projectdefectid&#34;]objectAtIndex:h];
      NSString *strBtnTag=;
      if ()
      {
            btnIndex=h;
         // NSLog(@&#34;%ld&#34;,(long)btnIndex);
            isTappedMarker=YES;

      }
    }
    NSMutableArray *indexPaths=[init];
    ];

      NSLog(@&#34;%@&#34;,arrDefectImages);

      NSLog(@&#34;numberOfRowsInSection: %ld&#34;,(long));
      ;

      ;
      ;
</code></pre>

<p>btnIndex 是我要扩展的节号。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我通过使用这个实现了类似的目标:</p>

<pre><code>func didTapOnHeader(tapGesture: UITapGestureRecognizer) {

    let view = tapGesture.view as! ViewHeader

    // collapse if already expended.
    if view.tag == self.dataBinder.selectedSection {

      //collaps the section
      self.dataBinder.selectedSection = nil
      self.tableView.reloadSections(NSIndexSet(index:view.tag), withRowAnimation: UITableViewRowAnimation.Automatic)

    }else {

      // collapse last selected section, at a time one section should be selected.
      self.dataBinder.selectedSection = nil
      self.tableView.reloadData()

      //expand plan details
      self.dataBinder.selectedSection = view.tag
      self.tableView.reloadSections(NSIndexSet(index:view.tag), withRowAnimation: UITableViewRowAnimation.Automatic)
    }
}


func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {

    let view = ViewHeader.instanceFromNib()
    view.tag = section
    let gesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.didTapOnHeader(_:)))
    view.addGestureRecognizer(gesture)

    //### Assignment ###
    view.planDescriptionLabel.text = plan.planDescription

    return view
}
</code></pre>

<p>这将关闭以前选择的部分,并且每次只展开一个部分。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何扩展单个特定部分?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40714580/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40714580/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何扩展单个特定部分?