-1

I am relatively new to xCode and I have 2 integer text labels Text1 and Text2 text.

I'm looking for some code that would compare if Text1.text is greater than Text2.text and then if another text field Text3.text would be equal to the value of Text1.text.

Appreciate any help.

user0321
  • 23
  • 3
Swany_08
  • 15
  • 3

3 Answers3

0

In the attributes inspector I assume. Select the text, go to attributes inspector (top right corner at the utility area, forth in a row. Looks like a square head with ears) and check the size.

Well, if you want xcode to check the size, you'll need to make an if or switch statement. Use enums like .fontSize

Burundanga
  • 668
  • 5
  • 15
0

The text fields are just views that display a string. You can access the string that they contain via the text property:

NSString *text1 = _text1.text;

Now you have the string that is displayed in the textview ( "34" for example)

You can use the NSString method intValue to turn this string into an integer:

int text1Value = [text1 intValue];

You can now compare the value of this to another integer:

if (text1Value > 42) {
    _textLargest.text = [NSString stringWithFormat:"%d", textValue1];
}

Main points:

  • Text fields are just views; you need to work with the data they are displaying rather than treat them as objects
  • You need to use the correct type for your comparison. The text field contains text but you need to convert it to a number to make it meaningful
  • You need to convert the number back into a string if you want it to appear in the text field's text property [NSString stringWithFormat:"%d", textValue1]
davbryn
  • 7,156
  • 2
  • 24
  • 47
0

You can take and compare the int values as follows

if([Text1.text intValue] > [Text2.text intValue] )
{
    Text3.text=[NSString stringWithFormat:"%@", Text1.text];
}
user4261201
  • 2,324
  • 19
  • 26