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 06-28-2010, 01:09 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 2
ashwinitangade is on a distinguished road
Question problem displaying my scrollview

HI I have been trying to display images on a scrollView using the code similar to sample code for scroll image below.
I have done the coding but without an interface builder.I don't want to use an interface builder as this code is a very small snippet of my code.My problem is the images do not get displayed on the simulator.
Please help!!!!! thanks in advance


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


- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 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)];
}

- (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;

NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%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];

[scrollView2 setBackgroundColor:[UIColor blackColor]];
[scrollView2 setCanCancelContentTouches:NO];
scrollView2.clipsToBounds = YES;
scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.jpg"]];
[scrollView2 addSubview:imageView];
[scrollView2 setContentSize:CGSizeMake(imageView.frame.size.wid th, imageView.frame.size.height)];
[scrollView2 setScrollEnabled:YES];
[imageView release];
}
ashwinitangade is offline   Reply With Quote
Old 06-28-2010, 03:20 PM   #2 (permalink)
CAM
Registered Member
 
Join Date: Feb 2009
Posts: 157
CAM is on a distinguished road
Default

I think it might be because you didn't specify the coordinates it needs to go to. For example

Code:
imageView.frame=CGRectmMake(0,0,imageView.frame.size.width, imageView.frame.size.height);
also if this was copy and pasted you have a typo here
Code:
[scrollView2 setContentSize:CGSizeMake(imageView.frame.size.wid th, imageView.frame.size.height)];
There is a space in width.
CAM is offline   Reply With Quote
Old 07-04-2010, 10:18 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 2
ashwinitangade is on a distinguished road
Default

Quote:
Originally Posted by CAM View Post
I think it might be because you didn't specify the coordinates it needs to go to. For example

Code:
imageView.frame=CGRectmMake(0,0,imageView.frame.size.width, imageView.frame.size.height);
also if this was copy and pasted you have a typo here
Code:
[scrollView2 setContentSize:CGSizeMake(imageView.frame.size.wid th, imageView.frame.size.height)];
There is a space in width.
hi thanks for the reply, but i did not copy paste the code... i have my own code ... difference between the example(attached zip) and my code is that i am not using the interface code.

Last edited by ashwinitangade; 07-04-2010 at 10:24 AM. Reason: attach file.
ashwinitangade is offline   Reply With Quote
Reply

Bookmarks

Tags
image grid view, scrolling, without interface builder

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: 327
7 members and 320 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
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 12:22 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0