菜鸟教程小白 发表于 2022-12-13 09:37:44

ios - 重新加载 searchResultsTableView 时自定义单元格错误


                                            <p><p>当我点击这个按钮-[搜索]时,弹出窗口。</p>

<p>如果我写下搜索词并单击搜索按钮,则数据将填充到 NSMutableArray 中。 </p>

<p>此 searchTable 使用“自定义单元格”。</p>

<p>我无法将“自定义单元格”与 NSMutableArray 中的数据结合起来。</p>

<p>重新加载“searchTableView”时出现错误。</p>

<p>我该怎么办?请帮帮我!~谢谢~</p>

<p>[错误]</p>

<blockquote>
<p>2011-10-31 20:56:52.915 TheBE abcd
2011-10-31 20:56:53.158 TheBE <strong>* Assertion failure in -, /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072
2011-10-31 20:56:53.159 TheBE <em></em></strong><em> Terminating app due to uncaught exception &#39;NSInternalInconsistencyException&#39;, reason: &#39;UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:&#39;
*</em>* First throw call stack:
(0x12a2052 0x1753d0a 0x124aa78 0xc712db 0x381ee3 0x382589 0x36ddfd 0x37c851 0x327322 0x12a3e72 0x29ba92d 0x29c4827 0x294afa7 0x294cea6 0x294c580 0x12769ce 0x120d670 0x11d94f6 0x11d8db4 0x11d8ccb 0x1fae879 0x1fae93e 0x2e8a9b 0x1d68 0x1cc5 0x1)</p>
</blockquote>

<hr/>

<上一页>

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

      //******自定义单元格*********/
      SearchContentCell *cell = (SearchContentCell *);

      ;
      ;
      ;
      ];
      ;

      …………
      cell.verseLabel.text = @"Test2";
      cell.contentLabel.text = @“测试”;
         …………

      返回单元格;

    }
    -(void)mockSearch:(NSString*)searchString
    {
      ;
      [请求设置实体:实体圣经];
   //
       //创建谓词
      NSString *wildcardedString = ;
      NSPredicate *predicate = ;

      [请求集合谓词:谓词];

      NSError *错误;
      NSMutableArray *mutableFetchResults = [ mutableCopy];
      if (mutableFetchResults == nil) {
         //处理错误;
            NSLog(@"eerror");
      }

      _data = mutableFetchResults;

         ;

    }
    -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

      [ self 模拟搜索:searchBar.text];

    }

</pre>

<p>我认为错误部分:</p>

<blockquote>
<p>;</p>
</blockquote></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果这确实是您的 <code>tableView:cellForRowAtIndexPath:</code> 方法的样子,那么如果 <code>dequeueReusableCellWithIdentifier:</code> 返回 nil,您将丢失分配新单元格的部分。</p ></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 重新加载 searchResultsTableView 时自定义单元格错误,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7962107/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7962107/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 重新加载 searchResultsTableView 时自定义单元格错误