0

I'm still pretty new at coding and am trying to combine the sample code from two projects.

Question:

Basically, I want to capture the name of the image file (all named card1.gif, card2.gif, etc) in the for loop and set it to the _imagename variable, so I can pass the file name to the facebook code to include the image with the post. Not really sure how to combine the FB code with the image display loop code.

Thanks for any help!!

CGRect newViewSize = Scroller.bounds;
int NumberOfImages = 20;
int i;
for(i=0;i<NumberOfImages;i++){

    if(i == 0){
        //Setup first picture
        UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
        NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
        [ImgView setImage:[UIImage imageNamed:FilePath]];
        [Scroller addSubview:ImgView];
    }else{
        //Setup the rest of the pictures
        newViewSize = CGRectOffset(ViewSize, Scroller.bounds.size.width, 0);
        UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
        NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
        [ImgView setImage:[UIImage imageNamed:FilePath]];
        [Scroller addSubview:ImgView];
    }
}

[self.view addSubview:Scroller];

}

- (IBAction)facebook:(id)sender {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];


        [controller setInitialText:@"Insert FB text here"];
        [controller addURL:[NSURL URLWithString:@"http://www.cnn.com"]];
        [controller addImage:[UIImage imageNamed:_imagename]];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}
Irfan
  • 4,301
  • 6
  • 29
  • 46
user3534305
  • 31
  • 1
  • 7
  • Every time the loop goes, do you want that specific image posted on facebook? Or do you want an array of the images so you can use them later? – Michael King Apr 15 '14 at 03:54
  • Everytime the loop goes, I want that specific image name so I can plug into my FB code and only use if the user clicks the FB icon to share that image. I have been playing around with arrays with no luck yet on modifications to this code. – user3534305 Apr 15 '14 at 04:00

1 Answers1

0
int amountOfPictures = 20;
NSMutableArray *arrayOfPictureNames = [NSMutableArray array];
for(int x = 0; x < amountOfPictures; x++) {
   [arrayOfPictureNames addObject:[NSString stringWithFormat:@"card%d.png", x]];


}

Now you should have an array full of names of pictures in that card1.png card2.png format.

Michael King
  • 640
  • 1
  • 6
  • 18
  • Thanks, I am playing around with the code and got the array into my loop but no luck pulling out a particular imagename to use in "[controller addImage:[UIImage imageNamed:_imagename]];" Since this line is not in the loop, I am not sure how to extract each picture name from the array to use in the FB image code. – user3534305 Apr 15 '14 at 05:12
  • I got it working - since my images were in a scroll view, I ended up stealing the page position number from the scroll code. 'code' - (void) postFacebook { int position; position = scrollView.contentOffset.x / 320; NSLog (@"position %i",position); switch (position) { case 0: _imagename = @"image01.png"; break; case 1: _imagename = @"image02.png"; break; case 2: _imagename = @"image03.png"; break; default: break; } – user3534305 Apr 15 '14 at 20:37