07-07-2010, 02:01 PM
#1 (permalink )
Registered Member
Join Date: Feb 2009
Posts: 218
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];
07-07-2010, 02:05 PM
#2 (permalink )
Tutorial Author
Join Date: Feb 2009
Posts: 223
Quote:
Originally Posted by
malaki1974
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
07-07-2010, 02:06 PM
#3 (permalink )
iPhone SDK learner
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
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];
07-07-2010, 02:07 PM
#4 (permalink )
Tutorial Author
Join Date: Feb 2009
Posts: 223
Quote:
Originally Posted by
mr tickle
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.
07-07-2010, 02:09 PM
#5 (permalink )
iPhone SDK learner
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
Quote:
Originally Posted by
mr tickle
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 *
07-07-2010, 02:13 PM
#6 (permalink )
Tutorial Author
Join Date: Feb 2009
Posts: 223
Quote:
Originally Posted by
Batman
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
07-07-2010, 02:22 PM
#7 (permalink )
Registered Member
Join Date: Feb 2009
Posts: 218
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...
07-07-2010, 06:52 PM
#8 (permalink )
Registered Member
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
Quote:
Originally Posted by
malaki1974
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.
07-07-2010, 08:02 PM
#9 (permalink )
Registered Member
Join Date: Feb 2009
Posts: 218
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.
07-07-2010, 08:53 PM
#10 (permalink )
iPhone SDK learner
Join Date: Feb 2010
Location: Illinois, USA
Posts: 421
Even though the documentation says CGFloats have to be passed in, I use ints and it works fine.
07-08-2010, 06:58 AM
#11 (permalink )
Registered Member
Join Date: Feb 2009
Posts: 218
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];
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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