0

Unable to add multiple url in for loop. how it is possible . if i can use single url without loop then its work . But not working in looping with multiple url . how can i solved this problem i tried below code :

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
        return _photos.count;
    }
    - (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
        if (index < _photos.count)
            return [_photos objectAtIndex:index];
        return nil;
    }


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSMutableArray *photos = [[NSMutableArray alloc] init];

        photos=[[NSMutableArray alloc]initWithObjects:@"http://gloucesterstage.com/_website/wp-content/uploads/2015/06/apples2.jpg",@"http://www.apple.com/ipad/home/images/social/og.jpg?201508031746",nil];
        MWPhoto *photo;

        for (int i=0;i<[photos count];i++) {
            photo = [MWPhoto photoWithURL:[NSURL URLWithString:photos[i]]];
            photo.caption = @"";
            [photos addObject:photo];
        }

        _photos = photos;
        MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
        UINavigationController *nc = [[UINavigationController alloc]     initWithRootViewController:browser];
        [browser showNextPhotoAnimated:YES];
        [browser showPreviousPhotoAnimated:YES];
        [self presentViewController:nc animated:YES completion:nil];

    }
Monika Patel
  • 2,287
  • 3
  • 20
  • 45

1 Answers1

1

It seems that you are trying to show the local photo. For that you will need to use below.

[photos addObject:[MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]]]];

Reference


Edit 1

As per your new update, you are using online images. Use below code.

NSMutableArray *photos = [[NSMutableArray alloc] init];
MWPhoto *photo;

NSMutableArray *anotherArrayWhereYouHaveImages=[[NSMutableArray alloc] initWithObjects:@"http://gloucesterstage.com/_website/wp-content/uploads/2015/06/apples2.jpg",@"http://www.apple.com/ipad/home/images/social/og.jpg?201508031746",nil];

for (int i=0;i<[anotherArrayWhereYouHaveImages count];i++) {
    photo = [MWPhoto photoWithURL:[NSURL URLWithString:[anotherArrayWhereYouHaveImages objectAtIndex:i]]];
    photo.caption = [NSString stringWithFormat:@"Photo %d", i];
    [photos addObject:photo];
}

self.photos = photos;

// Create browser
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

browser.displayActionButton = YES;
browser.displayNavArrows = YES;
browser.zoomPhotosToFill = NO;
browser.navigationController.navigationBarHidden = NO;
[browser setCurrentPhotoIndex:myPostForPhoto];

CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFade;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:browser animated:NO];
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • got same error : [MWPhoto length]: unrecognized selector sent to instance 0x7fc963f35920 2015-09-08 11:36:53.961 Salon[4599:85544] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MWPhoto length]: unrecognized selector sent to instance 0x7fc963f35920' – Monika Patel Sep 08 '15 at 06:07
  • i want to assign multiple image .. so i put in loop and got this error – Monika Patel Sep 08 '15 at 06:08
  • photo = [MWPhoto photoWithURL:[NSURL URLWithString:path_for_image]]; in this line what is " path_for_image " – Monika Patel Sep 08 '15 at 06:14
  • @Stela : Wait, I will update my code to match your code.. it will work then – Fahim Parkar Sep 08 '15 at 06:17
  • @Stela : Check my updated code... copy paste full Edit 1... It will work then – Fahim Parkar Sep 08 '15 at 06:19
  • @Stela : I checked this code and its working perfect – Fahim Parkar Sep 08 '15 at 06:20
  • your line `photos=[[NSMutableArray alloc]initWithObjects:@"http://glou` is wrong... you have to use another array name there... – Fahim Parkar Sep 08 '15 at 06:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89030/discussion-between-fahim-parkar-and-stela). – Fahim Parkar Sep 08 '15 at 06:21
  • @Stela : from where you are? you look stunning... :* – Fahim Parkar Sep 08 '15 at 06:26
  • Fahim Parkar.. but when 1st time view image .. image loading too slow .. so u have any solution for that?? And can we use " ASYNCIMAGEVIEW" for that – Monika Patel Sep 08 '15 at 06:38
  • @Stela : I checked and its working fine... may be your internet speed is slow.. Images are downloading Asynchronously... MWPhotoBrowser is already using [SDWebImage](https://github.com/rs/SDWebImage) – Fahim Parkar Sep 08 '15 at 06:56