The ModMyTM Family of Sites:
ModMyMotoModMyiModMyGphone




 
 
Register or Connect with Facebook

Discuss AppStore Apps | Browse / Search Cydia | MMi Cydia Stats




  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-21-2008, 10:49 PM
Green Apple
 
Join Date: Oct 2007
Posts: 54
Thanks: 5
Thanked 1 Time in 1 Post
Can't figure out what's wrong with this code

I'm new to programming on the iPhone, and programming in general. I've only used Visual Basic and MATLAB before, so this may sound a bit stupid.

So basically, I'm just getting experience on making apps for the iPhone, and I want to try to make an app that will fill up the screen with 1x1 pixel labels one label at a time.

Fill_ScreenAppDelegate.h

Code:
#import <UIKit/UIKit.h>

@interface Fill_ScreenAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	CGRect frame;
	UILabel *label;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

- (void)addPixel:(CGRect) frame

@end
Fill_ScreenAppDelegate.m

Code:
#import "Fill_ScreenAppDelegate.h"

@implementation Fill_ScreenAppDelegate

@synthesize window;

- (void)addPixel:(CGRect) frame {
	UILabel *label = [[UILabel alloc] initWithFrame:frame];
	[window addSubview:label];
	[label dealloc];
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

	int xx = 1;
	int yy = 1;

    while(yy <= 480) {
		
		while(xx<= 320) {
		if (xx < 320)
			xx = xx + 1;
			CGRect frame = [CGRectMake(xx, yy, 1, 1)];
			[Fill_ScreenAppDelegate addPixel:frame];

		}
		
		xx = 1;
		yy = yy + 1;
		
		CGRect frame = [CGRectMake(xx, yy, 1, 1)];
		[Fill_ScreenAppDelegate addPixel:frame];

	}
		
    [window makeKeyAndVisible];
}


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


@end
Here is an image of the warnings and errors :
Click the image to open in full size.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2  
Old 12-29-2008, 06:43 PM
NetMage's Avatar
Developer
 
Join Date: Aug 2007
Device + Firmware: iPhone 2.2.0
Operating System: Windows XP / OS X
Location: Virginia
Posts: 1,231
Thanks: 45
Thanked 202 Times in 162 Posts

First of all, I think creating 153,600 labels is likely to run the iPhone out of memory.

Second, CGRectMake is a function, not a message call, so should not be in brackets.

Third, Fill_ScreenAppDelegate is a class, not an object, which means it only responds to + messages, not - messages (hence the warning). Use the special name self to send a message to the current object.

Fourth, you should never call dealloc, you call release. The framework calls dealloc when it determines there are no more references to the released object to actually return memory.

Fifth, you don't need instance variables for frame and label since you are just using them locally in methods.

Sixth, you are resetting xx to one every time through your while loop on xx which means you won't get anywhere.

Attached is code that may compile (untested) but wouldn't bet on running:
Code:
#import "Fill_ScreenAppDelegate.h"

@implementation Fill_ScreenAppDelegate

@synthesize window;

- (void)addPixel:(CGRect) frame {
	UILabel *label = [[UILabel alloc] initWithFrame:frame];
	[window addSubview:label];
	[label release];
}

- (void)applicationDidFinishLaunching:(UIApplication*) application {

    int xx, yy;

    for (yy = 0; yy < 480; ++yy) {
        for (xx = 0; xx < 320; ++xx) {
	    CGRect frame = CGRectMake(xx, yy, 1, 1);
	    [self addPixel:frame];
	}
    }

    [window makeKeyAndVisible];
}

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

@end
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion

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



Go to Top
ModMyI

All times are GMT -6. The time now is 10:35 AM. Powered by vBulletin® Version 3.8.4
If you need Dedicated Server Hosting, you should check out SingleHop. | Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 Copyright © 2007-09 by ModMy, LLC. All rights reserved.

iPhone News / iPhone Forums / Apple News / Apple Forums / RSS / Contact Us / / Privacy Statement / Top