UIScrollView不显示第一个对象

UIScrollView不显示第一个对象,uiscrollview,nsmutablearray,Uiscrollview,Nsmutablearray,我目前有一个从阵列加载图像的滚动视图,下面是我的代码: icons = [[NSMutableArray alloc]initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"one" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"two"

我目前有一个从阵列加载图像的滚动视图,下面是我的代码:

icons = [[NSMutableArray alloc]initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"one" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"two" ofType:@"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"three" ofType:@"png"]],nil];

int numberOfItems = [icons count];
NSLog(@"Number of objects: %i",numberOfItems);

for (int i = 0; i < numberOfItems; i++) {

    if (i <= 3) {

        finalFrame = CGRectMake( i*(80), 12, 80, 80);
    }

    UIButton *iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    iconButton.frame = CGRectMake(0, 0, 57, 57);
    iconButton.center = CGPointMake(40, 29);
    iconButton.imageView.contentMode = UIViewContentModeScaleToFill;
    [iconButton addTarget:self action:@selector(selected:) forControlEvents:UIControlEventTouchUpInside];
    iconButton.tag = i;

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^{
        UIImage *icon = [icons objectAtIndex:i];
          dispatch_sync(dispatch_get_main_queue(), ^{
            [iconButton setImage:icon forState:UIControlStateNormal];
        });
    });

    [sub addSubview:iconButton];

    sub = [[UIView alloc] initWithFrame:finalFrame];
    [scrollView addSubview:sub];
}
icons=[[NSMutableArray alloc]initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“一”型:@“png”],[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“三”型:@“png”],[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@“三”型:@“png”],[nil];
int numberOfItems=[图标计数];
NSLog(@“对象数:%i”,numberOfItems);
对于(int i=0;i如果(i我认为它在for循环中,因为它应该是这样的

(int i = 0; i <= numberOfItems; i++)

(inti=0;i我认为它在for循环中,因为它应该是这样的

(int i = 0; i <= numberOfItems; i++)

(int i=0;i是你的代码给出了正确的对象数?是的,日志读取了数组中的三个对象,它们是。你的代码给出了正确的对象数吗?是的,日志读取了数组中的三个对象,它们是。不,在看到你的答案后,我认为你是对的,但一旦我更改了它,就会抛出一个超出索引的错误。不,在s之后看你的答案,我认为你是对的,但一旦我改变它抛出了一个超出索引的错误。