0

これは私の SlidesViewController.m ファイルです。たくさんの画像をにロードしようとしてUIPageViewControllerいますが、運がありません。下部の 2 つの点を除いて、画面は黒です。画像がありません。私が知る限り、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
4

1 に答える 1

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;
}
于 2012-11-14T05:46:57.430 に答える