我正在尝试将您的实现作为一个名为‘Gallery’的按钮实现到我的项目中,但在尝试运行该项目时收到错误。
我的实现文件如下所示。
-(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;
}当我运行项目,但图片库没有显示。我是ioS development.If的新手,如果您能告诉我正确的方向,我将不胜感激。主要目标是在用户触摸gallery按钮时显示图片库。
我复制并编辑了MWPhotoBrowser演示项目文件中的代码,我没有收到任何错误,但一旦触摸按钮,我就无法让图库出现。(顺便说一下,我给按钮分配了IBACTION )。如果有其他源代码或替代框架我可以使用,请告知。谢谢!
发布于 2012-03-02 08:18:21
一些想法:
1)尝试使用'initWithPhotos‘。
2)在推流的地方设置断点,检查是否调用了推流。
3)调试时检查navigationController不为空(0x0)。
4)记得释放'browser‘。
https://stackoverflow.com/questions/8897897
复制相似问题