gpt4 book ai didi

ios - [__NSArrayM objectAtIndex :]: index 2 beyond bounds [0 . 。 1]

转载 作者:行者123 更新时间:2023-11-28 18:10:14 26 4
gpt4 key购买 nike

我是一名新的 iOS 开发者;我有一个带有解析和动态单元格的应用程序,但是当我运行该应用程序时,我发现该应用程序由于标题上的原因而崩溃我的代码如下

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

myArray = [[NSMutableArray alloc] init];


//create new view if no view is available for recycling

// view = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 300.0f)] autorelease];

FXImageView *imageView = [[[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 350.0f)] autorelease];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.asynchronous = YES;
// imageView.reflectionScale = 0.5f;
// imageView.reflectionAlpha = 0.25f;
// imageView.reflectionGap = 10.0f;
imageView.shadowOffset = CGSizeMake(0.0f, 2.0f);
imageView.shadowBlur = 5.0f;
imageView.cornerRadius = 10.0f;
view = imageView;

[ProgressHUD dismiss];

NSString *string1 = [[NSUserDefaults standardUserDefaults] stringForKey:@"Class"];

PFQuery *query = [PFQuery queryWithClassName:[NSString stringWithFormat:@"%@",string1]];


query.cachePolicy = kPFCachePolicyNetworkElseCache;

//show loader view


[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {

myArray = [[NSMutableArray alloc] initWithArray:objects];

PFObject *object = [myArray objectAtIndex:index];


[file getDataInBackgroundWithBlock:^(NSData *data1, NSError *error) {
if (!error) {

((UIImageView *)view).image = [UIImage imageWithData:data1];

//[HUD hideUIBlockingIndicator];

}
}];

}

}];

return view;


}

我将第一屏 UICollectionView 与来自解析的动态数据一起使用,如下代码

pragma collectionView 委托(delegate)

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

CALayer *layer = cell.layer;
[layer setCornerRadius:8.0f];
[layer setMasksToBounds:YES];
// [layer setBorderWidth:1.0f];
// layer.backgroundColor = [UIColor whiteColor].CGColor;
//can you click

PFObject *imageObject = [myArray objectAtIndex:indexPath.item];
PFFile *imageFile = [imageObject objectForKey:@"image"];
NSString *name = [imageObject objectForKey:@"name"];

[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {

UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
imageView.image = [UIImage imageWithData:data];

UILabel *title2 = (UILabel *)[cell viewWithTag:200];
title2.text = [NSString stringWithFormat:@"%@",name];
title2.font = [UIFont fontWithName:@"GESSTextMedium-Medium" size:12];
}
}];


return cell;
}

我需要一些帮助才能知道错误在哪里;每次我在控制台上收到此错误时 [__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]

最佳答案

没有足够的信息。我们甚至不知道这次崩溃的确切线路。myArray 中对象的实际数量是多少?您在 collectionView:numberOfItemsInSection: 上返回的内容等等..

恕我直言,最简单的解决方案是调试此崩溃。并找出索引大于 objectAtIndex: 预期的原因。试试这个:

1) Open "Breakpoint navigator"

2) tap '+' button and choose "Add Exception Breakpoint" option

现在,应用程序将在调试时对任何异常使用此断点。

关于ios - [__NSArrayM objectAtIndex :]: index 2 beyond bounds [0 . 。 1],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26517585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com