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

ios - 在我的表格 View 中设置单元格时索引超出范围


                                            <p><p>在我的表格 View 中设置单元格时,我遇到了这个问题:</p>

<p><strong>日志:</strong></p>

<blockquote>
<p><strong>* Terminating app due to uncaught exception &#39;NSRangeException&#39;, reason: &#39;*</strong> -: index 5 beyond bounds &#39;
*** First throw call stack:
(0x18696afd8 0x1853cc538 0x1868491f0 0x100918a30 0x10091960c 0x18cddf114 0x18cddf32c 0x18cdcca30 0x18cde431c 0x18cb7c92c 0x18ca97158 0x189c87274 0x189c7bde8 0x189c7bca8 0x189bf7360 0x189c1e3c0 0x189c1ee8c 0x1869189a0 0x186916628 0x186846db4 0x1882b0074 0x18caff130 0x1006920bc 0x18585559c)
libc++abi.dylib: terminating with uncaught exception of type NSException</p>
</blockquote>

<pre><code>internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
    if (tableView == tableview) {
      let cell = tableView.dequeueReusableCell(withIdentifier: &#34;table&#34;, for: indexPath as IndexPath) as! homeTableViewCell

      if (titlearray.count != 0) {
            let tit: NSString = self.titlearray as! NSString

            print(&#34;titlearraytitlearray\(titlearray)&#34;)

            appDelegate.trendseetitarray = titlearray

            print(&#34;appDelegatetrendseearray\(appDelegate.trendseetitarray)&#34;)

            cell.treadingtitle.text! = tit as String
      }

      if (pricearray.count != 0) {
            let tit: NSString = self.pricearray as! NSString

            appDelegate.trendseepricearray = pricearray

            cell.trendingprice.text! = tit as String
      }

      if (addressarraylist.count != 0) {
            let tit: NSString = self.addressarraylist as! NSString

            appDelegate.addressarraylist = addressarraylist
      }

      if (imagearray.count != 0 &amp;&amp; imagearray.count != nil ) {
            print(imagearray)

            let roomurl=URL(string: &#34;\(imagearray)&#34;)
            //print(&#34;Room URL:\(roomurl!)&#34;)
            appDelegate.trendseeimagearray = imagearray

            cell.Trendingimg.sd_setImage(
                with: roomurl,
                placeholderImage: UIImage(named:&#34;no_image.png&#34;),
                options: SDWebImageOptions.refreshCached,
                completed: { (image1: UIImage?, error1: Error?, cacheType1: SDImageCacheType, imageURL1: URL?) -&gt; Void in
                }
            )

            cell.Trendingimg.clipsToBounds = true;
            cell.Trendingimg.sd_setImage(with: roomurl, completed: self.block1)
      }

      return cell
    }

    return UITableViewCell()
}
</code></pre>

<p><strong>错误:</strong></p>

<pre><code>if (addressarraylist.count != 0) {
    let tit: NSString = self.addressarraylist as! NSString

    appDelegate.addressarraylist = addressarraylist
}
</code></pre>

<p><strong>作为图片问题:</strong></p>

<p> <img src="/image/rn9pQ.png" alt="Click here"/> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你可以试试这个:-</p>

<pre><code>if self.addressarraylist.count &gt; indexPath.row {
    let tit: NSString = self.addressarraylist as! NSString
    appDelegate.addressarraylist = addressarraylist
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在我的表格 View 中设置单元格时索引超出范围,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44928339/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44928339/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在我的表格 View 中设置单元格时索引超出范围