Xcode:Array Count not Empty,但是Array索引是空的?

时间:2018-01-04 04:22:38

标签: ios objective-c arrays xcode

我最近注意到我的应用程序在加载UIImageView * SideButton1时开始崩溃,因为“索引2超出了空数组的范围”。

所以我做NSLog检查我是否已经下载了数据并正确放入数组。

NSLog(@"topbanner1:%@",delegate.sidebannerDetailsArray)下方返回8,但2018-01-04 12:18:03.320192+0800 topbanner1 8 2018-01-04 12:18:03.320429+0800 topbanner1:() NSLog(@"topbanner1 %lu ",sizeof(delegate.sidebannerDetailsArray)); NSLog(@"topbanner1:%@",delegate.sidebannerDetailsArray); UIImageView * SideButton1 = [UIImageView new]; [SideButton1 sd_setImageWithURL:[NSURL URLWithString:[[delegate.sidebannerDetailsArray objectAtIndex:2]objectForKey:@"bannerImage"]]]; } [SideButton1 setContentMode:UIViewContentModeScaleAspectFit]; [SideButton1 setFrame:CGRectMake(itemPriceLabel.frame.size.width-160,ItemTitleLabel.frame.size.height+ItemTitleLabel.frame.origin.y+10,180,45)]; UITapGestureRecognizer *singletap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openSideButton1URL:)]; [ItemTitleView addSubview:SideButton1]; 返回空。

if([[delegate.sidebannerDetailsArray objectAtIndex:2]objectForKey:@"bannerImage"] == NULL){
        [SideButton1 sd_setImageWithURL:[NSURL URLWithString:@"https://xxxxx.com//sidebanners/sidebanner3.gif"]];
    }else{
    [SideButton1 sd_setImageWithURL:[NSURL URLWithString:[[delegate.sidebannerDetailsArray objectAtIndex:2]objectForKey:@"bannerImage"]]];
    }

我不知道为什么计数为8但数组中没有数据。 我试图解决这个问题,但它不起作用:

{{1}}

有任何建议吗?

0 个答案:

没有答案