1

当我尝试将“MWPhotoBrowser”添加到我的照片浏览器项目时,我想制作一个照片网格视图,但是当我运行它时,它崩溃了,它移动了线程 1 断点 5.1,我在下面粘贴了我的代码

h.file 的代码:

#import <Foundation/Foundation.h>

#import "MWPhotoBrowser.h"
#import <AssetsLibrary/AssetsLibrary.h>


@interface DEMOSevenViewController : UIViewController <MWPhotoBrowserDelegate>
{
NSArray *_photos;
}
@end

m.file 的代码:

#import "DEMOSevenViewController.h"

#import "SDImageCache.h"

@interface DEMOSevenViewController ()


@end

@implementation DEMOSevenViewController



#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;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableArray *photos = [[NSMutableArray alloc] init];
    for (int i = 0; i < 12; i++)
{
    MWPhoto* photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle   mainBundle] pathForResource:@"photo5" ofType:@"jpg"]]];
    photo.caption = @"Fireworks";
    [photos addObject:photo];
}
    _photos = photos;
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;
    UINavigationController *nc = [[UINavigationController alloc]     initWithRootViewController:browser];
    nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nc animated:YES];

}



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

@end
4

1 回答 1

0
 - (void)viewDidLoad{
    [super viewDidLoad];
    [self performSelector:@selector(getAllPhoto) withObject:nil afterDelay:0.5];
}



  -(void)getAllPhoto{
    NSMutableArray *photos = [[NSMutableArray alloc] init];
    for (int i = 0; i < 12; i++)
    {
        MWPhoto* photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle   mainBundle] pathForResource:@"photo5" ofType:@"jpg"]]];
        photo.caption = @"Fireworks";
        [photos addObject:photo];
    }
    _photos = photos;
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;
    UINavigationController *nc = [[UINavigationController alloc]     initWithRootViewController:browser];
    nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nc animated:YES];
}
于 2014-03-05T10:36:29.633 回答