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 07-07-2010, 02:01 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 218
malaki1974 is on a distinguished road
Default Officially going crazy

What am I doing wrong here? When I click the button nothing happens. If I write in the 4 numbers I need in the cgrect it works. I want the cgrect location of the box to change.

Code:
	  homeButtons = [[NSArray alloc] initWithObjects:
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"180", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"280", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"380", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"480", nil],
					 nil];
	  
	  int newY = [[homeButtons objectAtIndex:0] objectAtIndex:0];
	  int newY = [[homeButtons objectAtIndex:1] objectAtIndex:1];
	  int newW = [[homeButtons objectAtIndex:2] objectAtIndex:2];
	  int newH = [[homeButtons objectAtIndex:3] objectAtIndex:3];
	  
	  NSLog(@"newX = %@", newX);
	   NSLog(@"newY = %@", newY);
	   NSLog(@"newW = %@", newW);
	   NSLog(@"newH = %@", newH);
	  
	   NSLog(@"button pressed was %@", btn );
	//  NSNumber *kValue = [[homeButtons objectAtIndex:1] objectAtIndex:0];
	  
    // Notice the view y coordinate is offscreen (480)
    // This hides the view
	// [self buildText:[homeButtons objectAtIndex:btn]];
	
	  self.view = [[[UIView alloc] initWithFrame:CGRectMake(newX, newY, newW, newH)] autorelease];
malaki1974 is offline   Reply With Quote
Old 07-07-2010, 02:05 PM   #2 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 223
mr tickle is on a distinguished road
Default

Quote:
Originally Posted by malaki1974 View Post
What am I doing wrong here? When I click the button nothing happens. If I write in the 4 numbers I need in the cgrect it works. I want the cgrect location of the box to change.

Code:
	  homeButtons = [[NSArray alloc] initWithObjects:
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"180", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"280", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"380", nil],
					 [[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"480", nil],
					 nil];
	  
	  int newY = [[homeButtons objectAtIndex:0] objectAtIndex:0];
	  int newY = [[homeButtons objectAtIndex:1] objectAtIndex:1];
	  int newW = [[homeButtons objectAtIndex:2] objectAtIndex:2];
	  int newH = [[homeButtons objectAtIndex:3] objectAtIndex:3];
	  
	  NSLog(@"newX = %@", newX);
	   NSLog(@"newY = %@", newY);
	   NSLog(@"newW = %@", newW);
	   NSLog(@"newH = %@", newH);
	  
	   NSLog(@"button pressed was %@", btn );
	//  NSNumber *kValue = [[homeButtons objectAtIndex:1] objectAtIndex:0];
	  
    // Notice the view y coordinate is offscreen (480)
    // This hides the view
	// [self buildText:[homeButtons objectAtIndex:btn]];
	
	  self.view = [[[UIView alloc] initWithFrame:CGRectMake(newX, newY, newW, newH)] autorelease];
as i understand, cgrects are made of floats, not ints
mr tickle is offline   Reply With Quote
Old 07-07-2010, 02:06 PM   #3 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
Batman is on a distinguished road
Default

NSNumber does not have the method initWithObjets:. Just use
Code:
homeButtons = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:0], 
[NSNumber numberWithInt:-480],
[NSNumber numberWithInt:511], 
[NSNumber numberWithInt:280], nil];
Batman is offline   Reply With Quote
Old 07-07-2010, 02:07 PM   #4 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 223
mr tickle is on a distinguished road
Default

Quote:
Originally Posted by mr tickle View Post
as i understand, cgrects are made of floats, not ints
homeButtons = [[NSArray alloc] initWithObjects:
[[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"180", nil],
[[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"280", nil],
[[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"380", nil],
[[NSNumber alloc] initWithObjects:@"0", @"-480", @"511", @"480", nil],
nil];


and i never remember an nsnumber being allocateable as an array like object

an nsnumber is a number, thats it, it doesnt have a pointer.
mr tickle is offline   Reply With Quote
Old 07-07-2010, 02:09 PM   #5 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
Batman is on a distinguished road
Default

Quote:
Originally Posted by mr tickle View Post

and i never remember an nsnumber being allocateable as an array like object

an nsnumber is a number, thats it, it doesnt have a pointer.
An NSNumber does have a pointer. That's why when you make it you use a *
Batman is offline   Reply With Quote
Old 07-07-2010, 02:13 PM   #6 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 223
mr tickle is on a distinguished road
Default

Quote:
Originally Posted by Batman View Post
An NSNumber does have a pointer. That's why when you make it you use a *
corrected, i just checked, i was thinking about ints
mr tickle is offline   Reply With Quote
Old 07-07-2010, 02:22 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 218
malaki1974 is on a distinguished road
Default

It is still not working although I appreciate everyone's replies.
It only seems to work if I explicitly type in numbers in the cgrect...
malaki1974 is offline   Reply With Quote
Old 07-07-2010, 06:52 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by malaki1974 View Post
It is still not working although I appreciate everyone's replies.
It only seems to work if I explicitly type in numbers in the cgrect...
Well, what does your code look like now that you have corrected the errors pointed out above? Maybe it "still doesn't work" because you "still haven't fixed it" as suggested.
RLScott is offline   Reply With Quote
Old 07-07-2010, 08:02 PM   #9 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 218
malaki1974 is on a distinguished road
Default

Classic response - I needed a laugh. Great use of quotes also.
I used a mix of NSNumber and then I ended up converting the indexofobject into a cgfloat (I think) before placing into the cgrectmake. Otherwise the CGRectMake wasn't seeing the array returns as floats. NSLog's had everything being returned but not as floats apparently.

I will post the working code tomorrow. Thanks for the help everyone.
malaki1974 is offline   Reply With Quote
Old 07-07-2010, 08:53 PM   #10 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
Batman is on a distinguished road
Default

Even though the documentation says CGFloats have to be passed in, I use ints and it works fine.
Batman is offline   Reply With Quote
Old 07-08-2010, 06:58 AM   #11 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 218
malaki1974 is on a distinguished road
Default

Code that is working for me and thanks again for the help everyone.

Code:
	  homeButtons = [[NSArray alloc] initWithObjects:
						[[NSArray alloc] initWithObjects:
						[NSNumber numberWithFloat:0],
						[NSNumber numberWithFloat:-480],
						 nil],
						[[NSArray alloc] initWithObjects:
						 [NSNumber numberWithFloat:511],
						 [NSNumber numberWithFloat:-480],
						 nil],
						[[NSArray alloc] initWithObjects:
						 [NSNumber numberWithFloat:373],
						 [NSNumber numberWithFloat:-480],
						 nil],
						[[NSArray alloc] initWithObjects:
						 [NSNumber numberWithFloat:0.1],
						 [NSNumber numberWithFloat:-480.0],
						 nil],
						nil];
	
	  NSNumber *newX = ([[homeButtons objectAtIndex:[btn floatValue]] objectAtIndex:0]);
	  CGFloat floatValue = [newX floatValue];
 self.view = [[[UIView alloc] initWithFrame:CGRectMake([newX floatValue], -480, newW, newH)] autorelease];
malaki1974 is offline   Reply With Quote
Reply

Bookmarks

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: 329
9 members and 320 guests
bignoggins, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
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:34 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0