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 6635557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:04:11+00:00 2026-05-25T23:04:11+00:00

I am making a fraction calculator app from the Programming In Objective-C 2.0 book.

  • 0

I am making a fraction calculator app from the Programming In Objective-C 2.0 book. I am using XCode 4.1 for Lion. I have completely and successfully without any error typed in the code. But when I press a number button while the app is running, the label doesn’t input any text. When I press a number button, it should find the UIButton senders tag (which I have allocated)

   -(IBAction)clickDigit:(UIButton *)sender {

int digit = sender.tag;

[self processDigit:digit];
    }

and it gets sent to this code:

  -(void)processDigit:(int)digit {

currentNumber = currentNumber * 10 + digit;

[displayString appendString:[NSString stringWithFormat:@"%i", digit]];
display.text = displayString;

NSLog(@"Processed");

    }

The console DOES print Processed. Indicating that this button is working, so the problem lies in this line of code:

[displayString appendString:[NSString stringWithFormat:@"%i", digit]];
display.text = displayString;

display is a UILabel, it is an instance variable but it is not an IBOutlet but is declared as an IBOutlet in its property.

@property (nonatomic, retain)IBOutlet UILabel *display;

I have connected the label on the .xib screen using the connection to code assistant thing. I can literally connect it to the declarations. So I connected it to the property.

Now, the problem lies in the fact that display is a UILabel and its text property requires an NSString not a NSMutableString right? But an NSString cannot append a string and many other methods that I need it to do for this app. How can I make this work?

  • 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-25T23:04:12+00:00Added an answer on May 25, 2026 at 11:04 pm

    NSMutableString and NSString are mostly interchangeable. I.e. if a method requires an NSString, you can pass it an NSMutableString. This doesn’t work the other way, though, and they are often copied and made immutable. i.e. even if you pass an NSMutableString to UILabel‘s text property, it will always return an NSString back.

    I suspect you’ve got some other issue going on here.
    That said, it’s often easier to work with immutable strings than mutable ones.

    You can change this code:

    [displayString appendString:[NSString stringWithFormat:@"%i", digit]];
    display.text = displayString;
    

    into this code:

    display.text = [displayString stringByAppendingString:[NSString stringWithFormat@"%i",digit]];
    

    Because stringByAppendingString makes a new immutable string object with the contents of the receiver (displayString) and the string passed as a parameter ([NSString stringWithFormat:@"%i",digit]).

    I suspect your issue is displayString is nil.
    Add some NSLog’s to find out…

    1. to -(IBAction)clickDigit:(UIButton *)sender add NSLog(@"Sender is %@",sender)
    2. to -(void)processDigit:(int)digit add NSLog(@"Digit is %i and displayString is %@ and display is %@", digit, displayString, display);

    This should give you an idea of what objects are nil, or badly connected in Interface Builder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView and basically I'm making some in app settings, and if
Suppose I’m making an Objective-C class that represents a fraction, and want to create
making a thumbnail from video using the picker is straight forward. However, when I
I have a custom Fraction class, which I'm using throughout my whole project. It's
Making a word document of our network set-up. We have about 7 servers and
On a site I'm making I need to have a progress bar, I found
Making a mobile friendly site, I have a single field and a submit button.
making a new jsp and got a mock-up from some analyst. Notice the sections
Making an Flex App. Just wondering if anyone has created something that fits automatically
I am making a fraction class for a school project, and my brain is

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.