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

  • SEARCH
  • Home
  • 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 8891923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:51:46+00:00 2026-06-14T22:51:46+00:00

I am making an iOS calculator and it I’m having minor difficulties with the

  • 0

I am making an iOS calculator and it I’m having minor difficulties with the backspace button (for deleting the last number of the value displayed on a label).

To get the current value on the label I use

    double currentValue = [screenLabel.text doubleValue]

Following other questions, I tried something like

-(IBAction)backspacePressed:(id)sender
{
NSMutableString *string = (NSMutableString*)[screenLabel.text];

int length = [string length];

NSString *temp = [string substringToIndex:length-1]
;

[screenLabel.text setText:[NSString stringWithFormat:@"%@",temp]];

}

But it does not work,

(Xcode says “setText is deprecated“, “NSString may not respond to setText” and that an identifier is expected in the first line of code inside the IBAction)

and I do not really understand this code to make it work by myself.

What should I do?

  • 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-06-14T22:51:47+00:00Added an answer on June 14, 2026 at 10:51 pm

    It should be

    [screenLabel setText:[NSString stringWithFormat:@"%@",temp]];
    

    Your Xcode clearly says that you are trying to call setText' method on anNSStringwhere as you should be calling that on aUILabel. YourscreenLabel.textis retuning anNSString. You should just usescreenLabelalone and should callsetText` on that.

    Just use,

    NSString *string = [screenLabel text];
    

    The issue with that was that, you are using [screenLabel.text]; which is not correct as per objective-c syntax to call text method on screenLabel. Either you should use,

    NSString *string = [screenLabel text];
    

    or

    NSString *string = screenLabel.text;
    

    In this method, I dont think you need to use NSMutableString. You can just use NSString instead.

    In short your method can be written as,

    -(IBAction)backspacePressed:(id)sender
    {
       NSString *string = [screenLabel text];
       int length = [string length];
       NSString *temp = [string substringToIndex:length-1];
       [screenLabel setText:temp];
    }
    

    As per your question in comments(which is deleted now), if you want to display zero when there are no strings present, try,

    -(IBAction)backspacePressed:(id)sender
    {
       NSString *string = [screenLabel text];
       int length = [string length];
       NSString *temp = [string substringToIndex:length-1];
    
       if ([temp length] == 0) {
         temp = @"0";
       }
       [screenLabel setText:temp];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to iOS development and I'm having trouble making a simple Json POST
I’m making an ios application and am having trouble using a switch statement to
I am making an iOS calculator app in which the scientific notion is enabled
New to iOS development and I'm just making a little wage-type calculator for a
I'm making an iOS game in Monotouch with C# and MonoDevelop. I'm having a
Possible Duplicate: ios making a button change view when text field equals string I
I'm making an iOS app that needs to load some youtube videos. I was
I'm making an iOS app using AIR 3.1 and Flex 4.5.1, and if I
I am making an AIR for iOS app that can download pdfs. I do
I'm making a webapp for iOS. When I make a dropdown list with the

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.