Ios Can';t将UIButton添加到UIScrollView

Ios Can';t将UIButton添加到UIScrollView,ios,objective-c,ipad,uiscrollview,uibutton,Ios,Objective C,Ipad,Uiscrollview,Uibutton,晚安 虽然我读过很多关于在UIScrollView中添加UIButton的相关问题,但对我来说并不适用。当我使用UIImages而不是UIButtons时,它就像一个符咒。我错过了什么?(不要介意if's或for循环,所有这些都是正确的,还有图像的路径) for(int j=0;j

晚安

虽然我读过很多关于在UIScrollView中添加UIButton的相关问题,但对我来说并不适用。当我使用UIImages而不是UIButtons时,它就像一个符咒。我错过了什么?(不要介意if's或for循环,所有这些都是正确的,还有图像的路径)

for(int j=0;j<[子类别计数];j++){
NSArray*产品=[子类别对象索引:(j)];
int posX=0;

for(int k=1;k
[UIImage imageNamed:path]
看起来不正确, 请尝试
[UIImage imageWithData:[NSData dataWithContentsOfFile:path]



在[fotoButton setImage:[UIImage IMAGENAME:path]forState:UIControlStateNormal];UIImage IMAGENAME部分不正确,请尝试添加此[UIImage imageWithData:[NSData DATAHWITH CONTENTS OFFILE:path];您刚刚成就了我的一天!谢谢!这确实是个错误。Thilina Hewagama也这么说。无论如何,谢谢!
 for(int j = 0; j < [subcategorie count]; j++){

        NSArray *product = [subcategorie objectAtIndex:(j)];
        int posX = 0;
        for(int k = 1; k <= [product count]; k++){

            if((i-1) == currentCategory ){
                //NSString *fotoName = [NSString stringWithFormat:@"images/product/%@/%@_%i.png",self.categorieen[(i-1)] ,self.categorieen[(i-1)] , k];

                NSString *fotoName = [NSString stringWithFormat:@"%@_%i",self.categorieen[(i-1)] , k];

                NSString *currentCategory = [NSString stringWithFormat:@"images/product/%@/", self.categorieen[(i-1)]];
                NSString *path = [[NSBundle mainBundle] pathForResource:fotoName ofType:@"png" inDirectory:currentCategory];

                UIButton *fotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
                [fotoButton setImage:[UIImage imageNamed:path] forState:UIControlStateNormal];
                fotoButton.frame = CGRectMake(posX, 252, 718, 520);
                fotoButton.backgroundColor = [UIColor clearColor];

                self.scrollview.contentSize = CGSizeMake(posX, 252);
                [self.scrollview setBounces:YES];
                [self.scrollview setPagingEnabled:YES];
                [self.scrollview addSubview:fotoButton];
                [self.scrollview bringSubviewToFront:fotoButton];
                [self.scrollview setUserInteractionEnabled:YES];

                self.scrollview.userInteractionEnabled = YES;
                [self addSubview: self.scrollview];
                posX += 718;

                NSLog(@"Fotolink = %@", fotoName);
            }

        }
    }
UIButton *fotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
[fotoButton setImage:[UIImage imageWithData:[NSData dataWithContentsOfFile:path] forState:UIControlStateNormal];