• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:11:37 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

日志:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]' *** 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

internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if (tableView == tableview) {
        let cell = tableView.dequeueReusableCell(withIdentifier: "table", for: indexPath as IndexPath) as! homeTableViewCell

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

            print("titlearraytitlearray\(titlearray)")

            appDelegate.trendseetitarray = titlearray

            print("appDelegatetrendseearray\(appDelegate.trendseetitarray)")

            cell.treadingtitle.text! = tit as String
        }

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

            appDelegate.trendseepricearray = pricearray

            cell.trendingprice.text! = tit as String
        }

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

            appDelegate.addressarraylist = addressarraylist
        }

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

            let roomurl=URL(string: "\(imagearray[indexPath.row])")
            //  print("Room URL:\(roomurl!)")
            appDelegate.trendseeimagearray = imagearray

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

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

        return cell
    }

    return UITableViewCell()
}

错误:

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

    appDelegate.addressarraylist = addressarraylist
}

作为图片问题:

Click here



Best Answer-推荐答案


你可以试试这个:-

if self.addressarraylist.count > indexPath.row {
    let tit: NSString = self.addressarraylist[indexPath.row] as! NSString
    appDelegate.addressarraylist = addressarraylist
 }

关于ios - 在我的表格 View 中设置单元格时索引超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44928339/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap