scrollview无法从数据库映像工作

时间:2013-08-08 10:36:10

标签: iphone ios uiscrollview uiimageview nsmutablearray

我在本地数据库中存储了一些图像。我使用sqlite从数据库中获取图像并使用数组显示。然后我将图像数组添加到scrollview中。但是scrollview无效。

代码:

.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];


    }

1 个答案:

答案 0 :(得分: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)];
}