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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:42:59+00:00 2026-06-06T08:42:59+00:00

Ok so I am like one day into learning objective c. I know this

  • 0

Ok so I am like one day into learning objective c. I know this is a really basic question, but it will help me with my learning greatly. So the code is just a basic counter, but I want to add something to it so when the counter reaches a certain number, a different message appears. I have tried many different things but I failed. Thanks in advance.

#import "MainView.h"

@implementation MainView

int count = 0;

-(void)awakeFromNib {

    counter.text = @"count";

}

- (IBAction)addUnit {

    if(count >= 999) return;

    NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count++];
    counter.text = numValue;
    [numValue release];
}

- (IBAction)subtractUnit {

    if(count <= -999) return;

    NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count--];
    counter.text = numValue;
    [numValue release]; {

    }


}
  • 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-06T08:43:00+00:00Added an answer on June 6, 2026 at 8:43 am

    First of all, instead of putting the count as a global variable, it’s more appropriate to put it in your interface instead. And regarding the question you have, your code should be changed to something like this.

    - (IBAction)addUnit {
    
        //if(count >= 999) return;  Delete this line, there is absolutely no point for this line this line to exist. Basically, if the count value is above 999, it does nothing.
    
        NSString *numValue;
        if (count>=999)
        {
            //Your other string
        }
        else
        {
            numValue = [[NSString alloc] initWithFormat:@"%d", count++];   
        }
        counter.text = numValue;
        [numValue release];//Are you using Xcode 4.2 in ARC?  If you are you can delete this line
    }
    

    Then you can change your other method to something similar.

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

Sidebar

Related Questions

hi I have a datepickerdialog but i´d like to change always one day before
How to create WPF Application Preloader (like one on this Word 2010 Prt Scrn)?
I have this dilemma many times - and I would like one time and
I am not an idiot, but header files make me feel like one sometimes.
I have one like this: CALayer *layer = stripeButton.layer; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@bounds.origin.y];
I am working on creating what I hope one day will be a publicly
I know many developers just do it like this: They start developing their app
I was just about to write this myself, but I know this has to
I'm really frustrated after spending like three hours googling around to solve this problem!!
cgi.escape seems like one possible choice. Does it work well? Is there something that

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.