-2

我在本地数据库中存储了一些图像。我使用 sqlite 从数据库中获取图像并使用数组显示。然后我将该图像数组添加到滚动视图中。但是滚动视图不起作用。

代码:

.h 文件:

NSMutableArray *arraysofs;
-(void)unloadPreviousPage:(int)index;
-(void)loadNextPage:(int)index;

.m 文件:

 -(void)click:(id)sender{


        scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        scroll.pagingEnabled = YES;



        for (int i = 0; i<[self.arraysofs count]; i++ ) {
            NSLog(@"index %d",i);



            mmageView=[[UIImageView alloc]initWithFrame:CGRectMake(20+(i*74), 420, 72, 72)];

           [mmageView setImage:((Mysof *) [self.arraysofs objectAtIndex:i]).photo];

           [scroll addSubview:mmageView];

          }


        [scroll setContentSize:CGSizeMake(CGRectGetMaxX(mmageView.frame),self.view.frame.size.height)];

       [self.view addSubview:scroll];


    }
4

1 回答 1

1

在您的 Click 方法中,设置滚动视图的内容大小,如下所示,

-(void)click:(id)sender{

for (int index = 0; index < [self.arraysofs count]; index ++ ) {
         NSLog(@"index %d",index);

        mmageView=[[UIImageView alloc]initWithFrame:CGRectMake(20+(index*74), 52, 72, 72)];

        [self.view addSubview:mmageView];

        Soflistsql * mysofs =[[Soflistsql alloc] init];
        self.arraysofs = [mysofs getMyLists];
        [mmageView setImage:((Mysof *) [self.arraysofs objectAtIndex:index]).photo];
    }

[your_ScrollView setContentSize:CGSizeMake(CGRectGetMaxX(mmageView.frame),self.view.frame.size.height)];
}
于 2013-08-08T10:56:04.963 回答