Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Skov

macrumors newbie
Original poster
Feb 13, 2011
3
0
Hey

i have a problem :-(

i have a simple tableView based app, i´m using core-data in my project.

i pub. the cell with a "name" and a number at subtitle, and i have made a button in the cell. the plan is that when the user push the button it will add the number from the "subtitle" to a NSNumber in my core data model, and if the value >= to X then it need to open a view.

i have don this, but nothing happens :-(

Code:
ToDo *toDo;
		
		int a = [toDo.pointsValue floatValue];
		int b = [toDo.totalPoint floatValue];
		 
		int c = a + b;
		
		toDo.totalPoint = [NSNumber numberWithInteger:c];
		
		if ([toDo.totalPoint floatValue] > [toDo.goodiesPoints floatValue]){
			
		CustomPickerViewController *addToDoView = [[CustomPickerViewController alloc] initWithNibName:@"CustomPickerViewController" bundle:[NSBundle mainBundle]];
		
		UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: addToDoView];
		[self.navigationController presentModalViewController:navController animated:YES];

hope u can help me out.
Skov
 
Last edited by a moderator:
NSNumber is a class which holds a representation of numeric types (including integers and floats) for the purpose of storage or transmission.

In your specific case I would suggest using the debugger, or placing NSLog statements before the conditional test, in order to understand the code paths.

Code:
// gcc -W -Wall -framework Foundation nsnumber.m
#import <Foundation/Foundation.h>

int main(void) {

	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSNumber* numberX = [NSNumber numberWithFloat:0.1];
	NSNumber* numberY = [NSNumber numberWithFloat:0.2];
	float     z       = [numberX floatValue] + [numberY floatValue];
	NSNumber* numberZ = [NSNumber numberWithFloat:z];

	NSLog(@"numberX:%f numberY:%f z:%f,%f", [numberX floatValue], [numberY floatValue], z, [numberZ floatValue]);

	[pool drain];
	return 0;
}
 
You're also mixing ints and floats pretty carelessly...it might not be the cause of your problem but it's ugly.
 
updte

did this after my fetch req.:


Code:
        NSNumber *a = toDoo.pointsValue;
	
	NSNumber *b = toDoo.totalPoint;
	
	CGFloat x = [a floatValue] + [b floatValue];
	
	
	//Note: it is better to use CGFloat rather than plain float
	CGFloat y = [toDoo.goodiesPoints floatValue];
	if (x >= y)
	{		
					
		[self performSelector:@selector(winView) 
					withObject:nil 
					afterDelay:0.5];
its like im missing something to make this work like i want:

if pointValue in tha cell is 10, the ideer is that u need to push that 5 times if goodiesPoints is set to 50. so it like im missing a way to set totalPoints to the new value ( x ) can u help me out ?
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.