當我嘗試添加'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
請出示次e crash log –
問題是您正試圖在ViewDidLoad中顯示MWPhotoBrowser。在viewDidAppear方法中添加此代碼 –
hello bro,謝謝你的建議,我已經將此代碼添加到ViewDidAppear方法,但是當我運行它時,它不顯示網格視圖。 – user3376284