Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-20-2010, 01:50 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 6
JakeSterage is on a distinguished road
Default An easy "how to" question. (Im really stuck now)

Ok, I'm trying to get two Scrollviews on the same view to scroll different images from the SAME NSArray of images on an iPad. Of course I can't simultaneous assign my array to two different names (as shown below). But what is the correct way of getting both scrollviews (scrollView1 and scrollView2) to read from the same array? Any help or a point in the right direction would save my life!

Here's my code with the NSArray incorrectly assigned twice:



#import "aprilViewController.h"

@implementation aprilViewController

@synthesize scrollView1, scrollView2;

const CGFloat kScrollObjHeight = 199.0;
const CGFloat kScrollObjWidth = 280.0;
const NSUInteger kNumImages = 6;


- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
NSArray *subviews = [scrollView2 subviews];


// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)


{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;

curXLoc += (kScrollObjWidth);
}
}

// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
[scrollView2 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView2 bounds].size.height)];
}

- (void)viewDidLoad

{
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;

scrollView1.pagingEnabled = YES;

self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
[scrollView2 setBackgroundColor:[UIColor blackColor]];
[scrollView2 setCanCancelContentTouches:NO];
scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView2.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView2.scrollEnabled = YES;

scrollView2.pagingEnabled = YES;

NSUInteger i;
for (i = 1; i <= kNumImages; i++)

{
NSString *imageName = [NSString stringWithFormat:@"isis%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[scrollView1 addSubview:imageView];
[imageView release];


[self layoutScrollImages];
}


NSString *imageName = [NSString stringWithFormat:@"itit%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[scrollView2 addSubview:imageView];
[imageView release];



}

- (void)dealloc
{
[scrollView1 release];
[scrollView2 release];

[super dealloc];
}

- (void)didReceiveMemoryWarning
{

[super didReceiveMemoryWarning];
}


@end
JakeSterage is offline   Reply With Quote
Reply

Bookmarks

Tags
nsarray, subview, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 328
7 members and 321 guests
Desert Diva, dre, hain, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0