0

I want to compare 2 numbers.

  1. The user has to enter a code(here 1) in and Textfield in an ViewController.
  2. The entered number will be compared with each other if it matches the app should switch to an other tab that is defined in each code.

and this is what i got so far

int a,b,c,zz;
a=1;
b=2;
c=3;

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (sender != self.done) 
      return;
    if (self.zahlencode.text.length > 0)
    {
       zz =self.zahlencode.text;
       if(zz == a)
       {
         zweiViewController *source = [segue sourceViewController];
       }
    }
}
Amar
  • 13,202
  • 7
  • 53
  • 71
user3429038
  • 1
  • 1
  • 3

3 Answers3

1

you can call intValue on your string:

NSString * intString = @"122";

int myInt = [intString intValue];

If from a textField:

int textFieldInt = [yourTextField.text intValue];

You can also use this for other types of value, like:

CGFloat textFieldFloat = [yourTextField.text floatValue];
double textFieldDouble = [yourTextField.text doubleValue];
// etc ...
Logan
  • 52,262
  • 20
  • 99
  • 128
0

Use like this

int myInt = [someString integerValue];
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
0
int a,b,c,zz;
a=1;
b=2;
c=3;

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (sender != self.done) 
      return;
    if (self.zahlencode.text.length > 0)
    {
       zz =[self.zahlencode.text intValue];
       if(zz == a)
       {
         zweiViewController *source = [segue sourceViewController];
       }
    }
}
m-farhan
  • 1,436
  • 13
  • 14