3

I did Get images for Url.and then display on SCrollView.My code like this

 NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
    for (NSDictionary *diction in al)
    {


       NSString *geting =[diction valueForKey:@"dealimage"];
        NSLog(@"dealimage is %@",geting);

        NSData *getdata=[[NSData alloc]initWithData:[NSData dataFromBase64String:geting]];
        NSLog(@"good day %@",getdata);
        dataimages=[UIImage imageWithData:getdata];
        NSLog(@"dataimages %@",dataimages);

        [imagesarray addObject:dataimages];


     }

scrollView=[[UIScrollView alloc]init];

    scrollView.delegate = self;
    scrollView.scrollEnabled = YES;
    int scrollWidth = 100;
    scrollView.contentSize = CGSizeMake(scrollWidth,100);
    scrollView.frame=CGRectMake(0, 0, 320, 100);
    scrollView.backgroundColor=[UIColor yellowColor];

    [self.view addSubview:scrollView];

    int xOffset = 0;
    imageView.image = [UIImage imageNamed:[imagesName objectAtIndex:0]];

    for(int index=0; index < [imagesName count]; index++)
    {

        UIImageView *img = [[UIImageView alloc] init];
        img.bounds = CGRectMake(10, 10, 50, 50);
        img.frame = CGRectMake(5+xOffset, 0, 160, 110);
        NSLog(@"image: %@",[imagesName objectAtIndex:index]);
        img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
        [images insertObject:img atIndex:index];
        scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110);

        [scrollView addSubview:[images objectAtIndex:index]];

        xOffset += 170;
    }

my Problem is ScrollView is Display but Images are not add So please tell me what wrong in my code

now i need like this image2

I know how to get images for Url.now i need display images Horizontal ScrollView So Please give me any idea about images .

BenMorel
  • 30,280
  • 40
  • 163
  • 285

4 Answers4

7

your coding is Fine, but you are assign the value of [scrollView addSubview:[images objectAtIndex:index]];, this is not the fine one, I modify your code, as per your result Want

UIScrollView  *scrollVie=[[UIScrollView alloc]init];

scrollVie.delegate = self;
scrollVie.scrollEnabled = YES;
int scrollWidth = 100;
//scrollVie.contentSize = CGSizeMake(scrollWidth,100);
scrollVie.frame=CGRectMake(0, 51, self.view.frame.size.width, 100);
scrollVie.backgroundColor=[UIColor redColor];




int xOffset = 0;

for(int index=0; index < [imagesarray count]; index++)
{

    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(xOffset,10,160, 110)];
    img.image = (UIImage*) [imagesarray objectAtIndex:index];

    [scrollVie addSubview:img];

    xOffset+=100;


}

[self.view addSubview:scrollVie];

scrollVie.contentSize = CGSizeMake(scrollWidth+xOffset,110);
Anbu.Karthik
  • 77,564
  • 21
  • 153
  • 132
2

"official" example created by Apple take a look at the StreetScroller Demo.

Hardik Kardani
  • 576
  • 3
  • 23
1

For the desired outcome that is shown in the picture, ie, the horizontal scroll, Use ScrollView instead of tableview.

set the pane of scroll to horizontal and dynamically create imageview inside a loop and insert images inside it

hope it helps :)

iosGuru
  • 11
  • 2
  • @iosGure thanks for Reply Please i am now to this Field Please give me any link about you'r answer –  Jul 19 '14 at 06:10
  • Check out the Apple documentation for scrollview.. Here is another link u can check it out [link](http://code4app.net/ios/PHSideScrollingImagePicker/526e82f46803fa9e06000001) **bold** – Saheb Roy Jul 19 '14 at 06:27
  • @iosGuru Please look once my question –  Jul 19 '14 at 08:57
  • @LightYagami Please look once my question –  Jul 19 '14 at 08:58
0

Instead of using table view why don't you user UICollectionView with their delegates.

you can refer this - Creating a UICollectionView programmatically

It's best way to achieve your requirement.

Community
  • 1
  • 1
Vikas Sawant
  • 106
  • 1
  • 8
  • thanks for reply i will try but i don't know about Scrollview On UICollectionViewCell please give me any link about that –  Jul 19 '14 at 06:07
  • Most welcome, why don't you go through this - [UIcollection view in detail](http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12) – Vikas Sawant Jul 19 '14 at 07:05
  • Please look once my question –  Jul 19 '14 at 08:56