Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式将UIImageView添加到UIScrollView_Ios_Iphone_Objective C_Uiscrollview_Uiimageview - Fatal编程技术网

Ios 以编程方式将UIImageView添加到UIScrollView

Ios 以编程方式将UIImageView添加到UIScrollView,ios,iphone,objective-c,uiscrollview,uiimageview,Ios,Iphone,Objective C,Uiscrollview,Uiimageview,我试图以编程方式创建包含UIImageView的UIScrollView。UIImageView的图像应该垂直滚动,我的问题是UIScrollView从未添加到我的主视图中。 这是密码 @property (strong, nonatomic) UIImageView *advertiseView; @property UIScrollView *sv; - (void)viewWillAppear:(BOOL)animated { [super viewWillApp

我试图以编程方式创建包含UIImageView的UIScrollView。UIImageView的图像应该垂直滚动,我的问题是UIScrollView从未添加到我的主视图中。 这是密码

@property (strong, nonatomic) UIImageView *advertiseView;
@property UIScrollView *sv;

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        _sv = [[UIScrollView alloc] init];

        _advertiseView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,568)];
        UIImage *image = [UIImage imageNamed:@"abc.png"];

        _advertiseView.image = image;
        _advertiseView.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.size};
        [_sv addSubview:_advertiseView];
        _sv.contentSize = CGSizeMake(320,1136); // size of abc.png
        [self.view addSubview:_sv];
    }

我遗漏了什么???

您没有设置ScrollView大小。试试这个:

_sv = [[UIScrollView alloc] initWithFrame:self.view.bounds];
int-width=0;
整数高度=0;

对于(int i=0;我是否检查了图像是否真的为非零?此外,我不认为您应该使用
viewwillbeen
更好地使用
viewDidLoad
,因为我认为您只想执行一次
int width = 0;
int height = 0;
for (int i=0; i<[menupicarray count]; i++)
{
    NSString *menupicname=[NSString stringWithFormat:@"%@",[menupicarray objectAtIndex:i]];
    UIImageView *imageView = [[UIImageView alloc] init ];
    [imageView setImageWithURL:[NSURL URLWithString:menupicname]
              placeholderImage:[UIImage imageNamed:@"NOmage.png"]];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.clipsToBounds = YES;
    imageView.frame = CGRectMake( MenuView.frame.size.width*i,0, MenuView.frame.size.width, MenuView.frame.size.height-5);
    [MenuView addSubview:imageView];
    width = imageView.frame.size.width;
    height = imageView.frame.size.height;
    MenuView.contentSize = CGSizeMake(width*i+imageView.bounds.size.width, height);
}