Question

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];
    }
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top