无法在 for 循环中添加多个 url。怎么可能。如果我可以使用没有循环的单个 url,那么它的工作。但不能循环使用多个 url 。我该如何解决这个问题,我尝试了下面的代码:
- (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];
}