2014-03-05 26 views
1

當我嘗試添加'MWPhotoBrowser'到我的照片瀏覽器項目,並且我想創建一個Photo Grid視圖,但是當我運行它時,它崩潰了,它表示線程1斷點5.1,我已經粘貼下面線程1斷點5.1在我的項目中使用MWPhotoBrowser時

代碼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 
+0

請出示次e crash log –

+0

問題是您正試圖在ViewDidLoad中顯示MWPhotoBrowser。在viewDidAppear方法中添加此代碼 –

+0

hello bro,謝謝你的建議,我已經將此代碼添加到ViewDidAppear方法,但是當我運行它時,它不顯示網格視圖。 – user3376284

回答

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]; 
} 
+0

哇,它的作品,你是如此的酷,非常感謝!但我想讓它顯示一個網格視圖,當我運行它,當點擊其中一個,點擊一個放大。我應該怎麼做?我向你展示Git.check上的WMPhotoBrowser在git上的m.file。 [https://github.com/mwaterfall/MWPhotoBrowser/blob/master/Demo/PhotoBrowserDemo/Menu.m] – user3376284

相關問題