Reputation: 1
im new to iphone, i have a two button left and right when i click left button to decrease the value in textfield and then i click right button to increase the value in textfield in iphone. please any one help me.
left button (num1.tag=10)
text1.text=[NSString stringwithformat:@"%d",num2.tag-1];
right button (num2.tag=11)
text1.text=[NSString stringwithformat:@"%d",num2.tag];
Upvotes: 0
Views: 466
Reputation: 19418
you can try this :
- (void) btnAction :(id) sender
{
if ([sender tag] == 10) //left button
{
int aNumber = [[text1 text] intValue];
aNumber = aNumber - 1 ;
text1.text=[NSString stringwithformat:@"%d",aNumber];
}
else if ([sender tag] == 11) //Right button
{
int aNumber = [[text1 text] intValue];
aNumber = aNumber + 1 ;
text1.text=[NSString stringwithformat:@"%d",aNumber];
}
}
Upvotes: 1
Reputation: 2707
convert the textValue to int and perform ur action
if(leftButton)
{
int newVal=[text1.text.text intValue]-1;
text1.text=[NSString stringwithformat:@"%d",newVal];
}
else
{
int newVal=[text1.text.text intValue]+1;
text1.text=[NSString stringwithformat:@"%d",newVal];
}
Upvotes: 0