0

I am trying to create a photo gallery with storyboards using MWPhotoBrowser. I have added a blue view to the first view but receive the error message

Thread 1:breakpoint 5.1:incompatible pointer types sending 'MWPhotoBrowser *' to parameter of type UIView.

Code:

In .h file:

#import <Foundation/Foundation.h>
#import "RESideMenu.h"

#import "MWPhotoBrowser.h"



@interface DEMOSevenViewController : UIViewController<MWPhotoBrowserDelegate>

@property (nonatomic, strong) NSMutableArray *photos;
@property (nonatomic, strong) NSMutableArray *thumbs;

@property (strong, nonatomic) UIView *container;

- (IBAction)showMenu;

@end

In .m file:

#import "DEMOSevenViewController.h"

@interface DEMOSevenViewController ()

@end

@implementation DEMOSevenViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *photos = [[NSMutableArray alloc] init];
NSMutableArray *thumbs = [[NSMutableArray alloc] init];
MWPhoto *photo;
BOOL displayActionButton = YES;
BOOL displaySelectionButtons = NO;
BOOL displayNavArrows = NO;
BOOL enableGrid = YES;
BOOL startOnGrid = NO;
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo5" ofType:@"jpg"]]];
photo.caption = @"White Tower";
[photos addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"jpg"]]];
photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
[photos addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo3" ofType:@"jpg"]]];
photo.caption = @"York Floods";
[photos addObject:photo];
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo4" ofType:@"jpg"]]];
photo.caption = @"Campervan";
[photos addObject:photo];
// Thumbs
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo5t" ofType:@"jpg"]]];
[thumbs addObject:photo];
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo2t" ofType:@"jpg"]]];
[thumbs addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo3t" ofType:@"jpg"]]];
[thumbs addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]     pathForResource:@"photo4t" ofType:@"jpg"]]];
[thumbs addObject:photo];
// Options
startOnGrid = YES;
self.photos = photos;
self.thumbs = thumbs;

// Create browser
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.displayActionButton = displayActionButton;
browser.displayNavArrows = displayNavArrows;
browser.displaySelectionButtons = displaySelectionButtons;
browser.alwaysShowControls = displaySelectionButtons;
browser.wantsFullScreenLayout = YES;
browser.zoomPhotosToFill = YES;
browser.enableGrid = enableGrid;
browser.startOnGrid = startOnGrid;
[browser setCurrentPhotoIndex:0];
UINavigationController *nc = [[UINavigationController alloc]     initWithRootViewController:browser];
nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nc animated:YES];
[_container addSubview:browser];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
return _photos.count;
}

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

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:    (NSUInteger)index {
if (index < _thumbs.count)
    return [_thumbs objectAtIndex:index];
return nil;
}

- (IBAction)showMenu
{
[self.sideMenuViewController presentMenuViewController];
}


@end
Adam Eberbach
  • 12,309
  • 6
  • 62
  • 114

1 Answers1

1

The problem is here, you are adding a ViewController and not a view where a View is expected.

[_container addSubview:browser];

Try:

[_container addSubview:browser.view];

Also, not entirely sure why you add it to a NavigationController and to _container depending on the rest of your code that might also cause problems, but the previous thing is what causes your error.

ophychius
  • 2,623
  • 2
  • 27
  • 49
  • thanks very very much, i have try [_container addSubview:browser.view]; and it didn't show the thread now, but when i click the Done button the photo collection view was disappear .and i want the photo browser could show on the blue view, can you tell me what should i do. please , and thank you again. – user3376284 Mar 17 '14 at 04:50
  • Maybe you could formulate that into a new question? With the code shown here I cannot tell much about your second question. Also, if you found the answer satisfactory, please accept it. – ophychius Mar 17 '14 at 09:35