Skip to content

Instantly share code, notes, and snippets.

@pnicholls
Created July 2, 2011 05:54
Show Gist options
  • Save pnicholls/1059776 to your computer and use it in GitHub Desktop.
Save pnicholls/1059776 to your computer and use it in GitHub Desktop.
#import "DataSource.h"
#import "SynthesizeSingleton.h"
@implementation DataSource
SYNTHESIZE_SINGLETON_FOR_CLASS(DataSource);
//
// init
//
// Init method for the object.
//
- (id)init
{
self = [super init];
if (self != nil)
{
dataPages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"],
nil];
}
return self;
}
- (NSInteger)numDataPages
{
return [dataPages count];
}
- (NSDictionary *)dataForPage:(NSInteger)pageIndex
{
return [dataPages objectAtIndex:pageIndex];
}
@end
//
// PageViewController.m
// Wallr
//
// Created by Peter Nicholls on 2/07/11.
// Copyright 2011 NA. All rights reserved.
//
#import "PageViewController.h"
#import "DataSource.h"
#import <QuartzCore/QuartzCore.h>
const CGFloat TEXT_VIEW_PADDING = 50.0;
@implementation PageViewController
@synthesize pageIndex;
- (void)setPageIndex:(NSInteger)newPageIndex
{
pageIndex = newPageIndex;
if (pageIndex >= 0 && pageIndex < [[DataSource sharedDataSource] numDataPages])
{
NSDictionary *pageData =
[[DataSource sharedDataSource] dataForPage:pageIndex];
// HOW DO I CONNECT MY IMAGE IN THE ARRAY UP TO MY OUTLET image_one
CGRect absoluteRect = [self.view.window
convertRect:textView.bounds
fromView:textView];
if (!self.view.window ||
!CGRectIntersectsRect(
CGRectInset(absoluteRect, TEXT_VIEW_PADDING, TEXT_VIEW_PADDING),
[self.view.window bounds]))
{
textViewNeedsUpdate = YES;
}
}
}
- (void)updateTextViews:(BOOL)force
{
if (force ||
(textViewNeedsUpdate &&
self.view.window &&
CGRectIntersectsRect(
[self.view.window
convertRect:CGRectInset(textView.bounds, TEXT_VIEW_PADDING, TEXT_VIEW_PADDING)
fromView:textView],
[self.view.window bounds])))
{
for (UIView *childView in textView.subviews)
{
[childView setNeedsDisplay];
}
textViewNeedsUpdate = NO;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment