¿Cómo incremento el valor en el campo de texto?

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];

preguntado el 08 de noviembre de 11 a las 12:11

or u can connect the buttons to different method.(ie)one method which increase value and put the value in textfield and another to decrease and display -

2 Respuestas

puedes probar esto:

- (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];
       }
 }

respondido 08 nov., 11:16

plz format my answer... I could not format it because : meta.stackexchange.com/questions/111348/… - Maulik

@user1006445 : you have to take care of '0' on submission...put proper validation to check '0' - Maulik

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];
}

respondido 08 nov., 11:16

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.