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

RobertD63

macrumors 6502
Original poster
Feb 17, 2008
403
42
A place
I've read (and viewed) the whole video and book of "Programming in Obj-c 2.0". Im trying to build a simple little program to increase the label +1 in a number when tapped increased and the opposite when you decrease. Everything is set up Im just trying to figure out what to put into the @implementation side. Heres what I have:
Code:
@implementation AppDelegate_Phone

@synthesize window,view,increaseButton,decreaseButton,numberOfSidesChange;

-(IBAction)increase {
	
	
}

-(IBAction)decrease {
	
	
}

//More code.....
Code:
@interface AppDelegate_Phone : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	UIView *view;
	IBOutlet UIButton *decreaseButton;
	IBOutlet UIButton *increaseButton;
	IBOutlet UILabel *numberOfSidesChange;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIView *view;
@property (nonatomic, retain) IBOutlet UIButton *increaseButton;
@property (nonatomic, retain) IBOutlet UIButton *decreaseButton;
@property (nonatomic, retain) IBOutlet UILabel *numberOfSidesChange;

-(IBAction)increase;
-(IBAction)decrease;

@end
So what would I use?
 
Code:
-(IBAction)increase {
	numberOfSidesChange.text = numberOfSidesChange.text + 1;
	
}

-(IBAction)decrease {
	numberOfSidesChange.text = numberOfSidesChange.text - 1;
	
}

except that you'll need to convert numberOfSidesChange.text to an int on the right hand side of the assignment, then do the add or subtract, then convert back to text.

I'm too lazy to look at my old code, but I've done it several times.
 
Code:
-(IBAction)increase {
	numberOfSidesChange.text = numberOfSidesChange.text + 1;
	
}

-(IBAction)decrease {
	numberOfSidesChange.text = numberOfSidesChange.text - 1;
	
}

except that you'll need to convert numberOfSidesChange.text to an int on the right hand side of the assignment, then do the add or subtract, then convert back to text.

I'm too lazy to look at my old code, but I've done it several times.
That seems a little more complicated then what I've been playing with here:
Code:
@implementation AppDelegate_Phone

@synthesize window,view,increaseButton,decreaseButton,numberOfSidesChange;
int number;

-(IBAction)increase {
number = number+1;	
numberOfSidesChange.text=number;	
}

-(IBAction)decrease {
number = number-1;
numberOfSidesChange.text=number;
	
}
 
How is number defined?

Besides, it's gonna have to be somewhat complicated because you are needing to convert a number to an NSString, in a manner of speaking, since that's what class type a UILabel's text property is.
 
How is number defined?

Besides, it's gonna have to be somewhat complicated because you are needing to convert a number to an NSString, in a manner of speaking, since that's what class type a UILabel's text property is.
Oh, so its not so simple after all. Well for me. Just wondering if I chose the wrong kind of thing to get my feet wet with iPhone apps etc?

At any rate im still interested in finishing this. How would I convert it to an NSString? If I did would I have to convert it back to an integer?
 
At any rate im still interested in finishing this. How would I convert it to an NSString? If I did would I have to convert it back to an integer?

Well, how about you use an int to to represent the number of sides and do your calculations on. Only convert it to NSString (hint: look for StringWithFormat: ) to display it... no need to convert backwards and forwards.
 
Ah hah! Got it!
Code:
-(IBAction)decrease {
	number=number-1;
	numberOfSidesChange.text = [NSString stringWithFormat:@"%d", number];

}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.