Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:52:37+00:00 2026-05-25T10:52:37+00:00

New to OB-C here. Java programmer by trade. This is a sample from my

  • 0

New to OB-C here. Java programmer by trade.

This is a sample from my view.m file. I have a display that takes some numbers from buttons.
If the display is showing 0, it should clear the 0 first before appending new numbers.

- (IBAction) btn1:(id) sender{[self numPress: (NSString *) @"1"];};
- (IBAction) btnClear:(id) sender{display.text = @"0";};

- (void) numPress : (NSString *) key {
    if (display.text ==  (NSString *) @"0")
        display.text = @"";
    display.text =  [display.text stringByAppendingString: key];
}

- (void) viewDidLoad {
    self.display.text = (NSString *) @"0";
}

When I run it as shown, the display sets to ‘0’ then if I hit ‘1’ the display changes to ’01’.
If I press Clear the display resets to ‘0’, then I if hit ‘1’ again, it changes to ‘1’. (the intended result). The first time I pressed ‘1’ the 0 should have been removed.

If I change the viewDidLoad to set the display.text to ‘2’ and change the numPress if statement condition to ‘2’ it works.

- (IBAction) btn1:(id) sender{[self numPress: (NSString *) @"1"];};
- (IBAction) btnClear:(id) sender{display.text = @"0";};

- (void) numPress : (NSString *) key {
    if (display.text ==  (NSString *) @"2")
        display.text = @"";
    display.text =  [display.text stringByAppendingString: key];
}

- (void) viewDidLoad {
    self.display.text = (NSString *) @"2";
}

I build then run and the display says ‘2’. I press ‘1’ and the display changes to ‘1’. (clearing the leading ‘2’ as it should).

Can someone help me here, why does ‘2’ work, but ‘0’ fails (but only the fist time), that boggles my mind?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:52:38+00:00Added an answer on May 25, 2026 at 10:52 am

    Use -isEqualToString: instead of comparing pointers (with ==).

    if ([display.text isEqualToString:@"..."])
        /* ... */ ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has to be a common question that all programmers have from time to
I have this xml file and I want to get some values with Xpath.
My colleague here argues that new programmers must learn ASP first, before they learn
Im new into that asp.net thing, but here goes. I got at ImageButton, and
I'm a fairly competent Java programmer who's very new to C. I am trying
I'm not a java programmer, I'm a VB programmer. I am doing this as
I am not an experienced Java programmer and i'm trying to write some text
I'm a .NET programmer doing some Hadoop work in Java and I'm kind of
I'm a Scala/Java programmer looking to reintroduce myself to C++ and learn some of
I have found this example on StackOverflow: var people = new List<Person> { new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.