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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 09-06-2009, 07:38 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 18
Default Allocation of memory within app

It seems i'm not allocating any memory at all in my application.

Here is my code.

Code:
#import "ApotheosisViewController.h"

@implementation ApotheosisViewController

@synthesize scrollView1;

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

const CGFloat kScrollObjHeight	= 320.0;
const CGFloat kScrollObjWidth	= 480.0;
const NSUInteger kNumImages		= 40;


- (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 = UIScrollViewIndicatorStyleBlack;
	scrollView1.clipsToBounds = NO;		// default is NO, we want to restrict drawing within our scrollview
	scrollView1.scrollEnabled = YES;
	
	// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
	// if you want free-flowing scroll, don't set this property.
	scrollView1.pagingEnabled = YES;
	
	// load all the images from our bundle and add them to the scroll view
	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];
		
		// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
		CGRect rect = imageView.frame;
		rect.size.height = kScrollObjHeight;
		rect.size.width = kScrollObjWidth;
		imageView.frame = rect;
		imageView.tag = i;	// tag our images for later use when we place them in serial fashion
		[scrollView1 addSubview:imageView];
		[imageView release];
}
	[self layoutScrollImages];	// now place the photos in serial layout within the scrollview
	
}

- (void)dealloc
{	
	[scrollView1 release];
	
	[super dealloc];
}

- (void)didReceiveMemoryWarning
{
	// invoke super's implementation to do the Right Thing, but also release the input controller since we can do that	
	// In practice this is unlikely to be used in this application, and it would be of little benefit,
	// but the principle is the important thing.
	//
	[super didReceiveMemoryWarning];
}

@end
The line of code that is giving me trouble is this one.

Code:
UIImage *image = [UIImage imageNamed:imageName];
I'm a newbie and i'm impressed i got this far but the memory allocation really has me by the balls. any help would be awesome.

I have all my images named like so:

image1, image,2, image3, etc
shadylane315 is offline   Reply With Quote
Old 09-07-2009, 01:16 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 29
Default

Like you said, you have to allocate memory for the class you're making an object off.

Try something like this:

Code:
CGRect imageRect = CGRectMake(0, 0, 1600, 1200);
myImage = [[UIImageView alloc] initWithFrame:imageRect];
[myImage setImage:[UIImage imageNamed:@"picture.jpg"]];
harryvermeulen is offline   Reply With Quote
Old 09-07-2009, 03:34 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 18
Default

ok awesome. Would i have to repeat this for all 40 images?

Quote:
Originally Posted by harryvermeulen View Post
Like you said, you have to allocate memory for the class you're making an object off.

Try something like this:

Code:
CGRect imageRect = CGRectMake(0, 0, 1600, 1200);
myImage = [[UIImageView alloc] initWithFrame:imageRect];
[myImage setImage:[UIImage imageNamed:@"picture.jpg"]];
shadylane315 is offline   Reply With Quote
Reply

Bookmarks

Tags
allocation, comic, images, iphone, memory

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: 323
21 members and 302 guests
@sandris, ADY, dacapo, Dani77, djohnson, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

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