这是我的SlidesViewController.m文件。我正在尝试将一堆图像加载到UIPageViewController
但我没有运气。除了底部的两个点外,屏幕是黑色的。没有图像,据我所知,我无法在2个视图之间切换。
我从NSLog
行获得的输出是
2012-11-13 20:25:10.535 [17680:c07] Slide show guid: ab7718c9-3495-4882-a1e3-71f39530963b
2012-11-13 20:25:10.536 [17680:c07] Loading image: /Users/Me/Library/Application Support/iPhone Simulator/6.0/Applications/667EF28E-4E5F-4452-BF0E-336730C2D3FE/Documents/media/dh1.jpg
2012-11-13 20:25:10.536 [17680:c07] Loading image: /Users/Me/Library/Application Support/iPhone Simulator/6.0/Applications/667EF28E-4E5F-4452-BF0E-336730C2D3FE/Documents/media/dh2.jpg
2012-11-13 20:25:10.538 [17680:c07] presentationCountForPageViewController: 2
2012-11-13 20:25:10.538 [17680:c07] presentationIndexForPageViewController: 0
不确定从哪里开始。
#import "SlidesViewController.h"
#import "SQLiteManager.h"
@interface SlidesViewController ()
@property (nonatomic, strong) NSMutableArray *imageViews;
@end
@implementation SlidesViewController
@synthesize guid = _guid;
@synthesize imageViews = _imageViews;
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Slide show guid: %@", self.guid);
self.dataSource = self;
// Get the system paths
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *mediaDir = [docsDir stringByAppendingPathComponent:@"media"];
// Grab the images from the database
SQLiteManager *db = [[SQLiteManager alloc] initWithDatabaseNamed:@"local.db"];
[db openDatabase];
NSString *sql = [NSString stringWithFormat:@"select * from pictures where point='%@' order by rank", self.guid];
NSArray *pictures = [db getRowsForQuery:sql];
// Create the views
self.imageViews = [[NSMutableArray alloc] initWithCapacity:[pictures count]];
for (NSDictionary *picture in pictures)
{
NSString *filename = [mediaDir stringByAppendingPathComponent:[picture objectForKey:@"imagename"]];
NSLog(@"Loading image: %@", filename);
UIImage *img = [[UIImage alloc] initWithContentsOfFile:filename];
UIImageView *iv = [[UIImageView alloc] initWithImage:img];
UIViewController *ivc = [[UIViewController alloc] init];
ivc.view = iv;
[self.imageViews addObject:ivc];
}
}
- (NSUInteger)indexOfViewController:(UIView *)view
{
return [self.imageViews indexOfObject:view];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSLog(@"viewControllerBeforeViewController");
int index = [self.imageViews indexOfObject:viewController] - 1;
if (index >= 0)
return [self.imageViews objectAtIndex:index];
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSLog(@"viewControllerAfterViewController");
int index = [self.imageViews indexOfObject:viewController] + 1;
if (index < [self.imageViews count])
return [self.imageViews objectAtIndex:index];
return nil;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
NSLog(@"presentationIndexForPageViewController: %d", 0);
return 0;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
NSLog(@"presentationCountForPageViewController: %d", [self.imageViews count]);
return [self.imageViews count];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL) gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (index==0) {
if ([(UIPanGestureRecognizer*)gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[(UIPanGestureRecognizer*)gestureRecognizer velocityInView:gestureRecognizer.view].x > 0.0f) {
NSLog(@"DENIED SWIPE PREVIOUS ON FIRST PAGE");
return NO;
}
if ([(UITapGestureRecognizer*)gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] &&
[(UITapGestureRecognizer*)gestureRecognizer locationInView:gestureRecognizer.view].x < self.view.frame.size.width/2) {
NSLog(@"DENIED TAP PREVIOUS ON FIRST PAGE");
return NO;
}
}
return YES;
}
@end
答案 0 :(得分:0)
在pageviewcontroller.m
中试试在.h
中使用UIGestureRecognizerDelegate- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (index==0) {
if ([(UIPanGestureRecognizer*)gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[(UIPanGestureRecognizer*)gestureRecognizer velocityInView:gestureRecognizer.view].x > 0.0f) {
NSLog(@"DENIED SWIPE PREVIOUS ON FIRST PAGE");
return NO;
}
if ([(UITapGestureRecognizer*)gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] &&
[(UITapGestureRecognizer*)gestureRecognizer locationInView:gestureRecognizer.view].x < self.view.frame.size.width/2) {
NSLog(@"DENIED TAP PREVIOUS ON FIRST PAGE");
return NO;
}
}
return YES;
}