wilforeal
wilforeal

Reputation: 369

MWPhotoBrowser used in button (Xcode)

Im trying to implement your implementation to my project as a button called 'Gallery" but receive an error when trying to run the project.

My implementation file looks like this.

-(IBAction) gallery{


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

MWPhoto *photo;

{

    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"fans1" ofType:@"jpg"]];

    photo.caption = @"My fans 1";

    [photos addObject:photo];

    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"fans2" ofType:@"jpg"]];

    photo.caption = @"My fans 2";

    [photos addObject:photo];

    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"fans3" ofType:@"jpg"]];

    photo.caption = @"Fans3";

    [photos addObject:photo];

    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"fans4" ofType:@"jpg"]];

    photo.caption = @"Fans4";

    [photos addObject:photo];


}






  self.photos = photos;



     // Create browser

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

browser.displayActionButton = YES;

  //browser.wantsFullScreenLayout = NO;

  //[browser setInitialPageIndex:2];



  // Show

  if (_segmentedControl.selectedSegmentIndex == 0) {

// Push

[self.navigationController pushViewController:browser animated:YES];

  } else {

// Modal

UINavigationController *nc = [[UINavigationController alloc]              initWithRootViewController:browser];

   nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:nc animated:YES];

   }

  }

  #pragma mark - MWPhotoBrowserDelegate

  - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {

   return _photos.count;

     }



  - (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:   (NSUInteger)index {

      if (index < _photos.count)

       return [_photos objectAtIndex:index];

   return nil;

  }

When I run the project but the image gallery is not displayed. Im fairly new to ioS development.If you can please point me in the right direction i will deeply appreciate it. The main goal is to have the image gallery displayed when the user touches the Gallery button.

I copied and edited the code from the MWPhotoBrowser Demo Project File I don't receive any errors but I can't get the gallery to appear once button is touched. (BTW I assigned the IBACTION to the buttons). If there is another source code or alternative Framework I can use please advise. Thanks!

Upvotes: 1

Views: 507

Answers (1)

karmington
karmington

Reputation: 204

Some Ideas:

1) try using 'initWithPhotos'.

2) put a breakpoint at the place you are pushing, check that the push is called.

3) check that the navigationController is not null (0x0) in debugging.

4) remember to release 'browser'.

Upvotes: 1

Related Questions