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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:56:10+00:00 2026-06-08T10:56:10+00:00

For a school assignment I have been told to make a calculator app, the

  • 0

For a school assignment I have been told to make a calculator app, the same as the spotlight calculator. It works in realtime and has no buttons for things to begin.

So far this is my code. It is written in a text field with the event Editing Did End. Im pretty sure thats wrong but i can’t find an alternative solution. Also i haven’t gotten the realtime thing to work so i’ve kind of reverted to completing the following steps when pressed off the text field.

- (IBAction)Didend_Action:(id)sender {
  NSString *list = [Sum_TextField text]; 
  NSArray *listItemsArray = [list componentsSeparatedByString:@" "];
  float firstNumber = [[listItemsArray objectAtIndex: 0] floatValue]; 
  NSString *symbol = [listItemsArray objectAtIndex: 1];
  float secondNumber = [[listItemsArray objectAtIndex: 2] floatValue];
  {   
    Calculator* calc = [[Calculator alloc] init];
    [calc setNum1:firstNumber];
    [calc setNum2:secondNumber];
    if ([symbol isEqualToString:@"-"])
    {
        [calc minus];
    }
    else if ([symbol isEqualToString:@"+"])
    {
        [calc add];
    } 
    if ([symbol isEqualToString:@"*"])
    {
        [calc multiply];
    }
    else if ([symbol isEqualToString:@"/"])
    {
        [calc divide];

    }
    [Answer_TextField setText:[NSString stringWithFormat:@"%d", [calc answer]]];  
  }
}
  • 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-08T10:56:12+00:00Added an answer on June 8, 2026 at 10:56 am

    I think a better way to do it would be to implement the UITextViewDelegate protocol methods like textViewDidChange:. For example, you could do something like this:

    - (void)textViewDidChange:(UITextView *)textView {
    
        NSString *currentText = [textview text];
        NSArray *currentItems = [currentText componenetsSeparatedByString:@" "];
        float result = 0.0;
    
        //If a valid expression is in the text view
        if([currentItems count] > 2) {
    
            float num1 = [[currentItems objectAtIndex:0] floatValue];
            float num2 = [[currentItems objectAtIndex:2] floatValue];
            NSString *operator = [currentItems objectAtIndex:1];
    
            if([operator isEqualToString:@"+"]) {
    
                result = num1 + num2;
                answerTextField.text = [NSString stringWithFormat:@"%f", result];
            }
            else if([operator isEqualToString:@"-"]) {
    
                result = num1 - num2;
                answerTextField.text = [NSString stringWithFormat:@"%f", result];
            }
            else if([operator isEqualToString:@"*"]) {
    
                result = num1 * num2;
                answerTextField.text = [NSString stringWithFormat:@"%f", result];
            }
            else if([operator isEqualToString:@"/"]) {
    
                result = num1 / num2;
                answerTextField.text = [NSString stringWithFormat:@"%f", result];            
            }
            else{
    
                answerTextField.text = @"Invalid Operation";
            }
        }
    } 
    

    This would be called every time the user edited the text in the text view. It should work, but I didn’t test it out. Make sure that in the header of whatever file this code is in, you do this:

    @interface yourClassName : yourSuperclass <UITextViewDelegate> {
    
        //Your instance variables
    }
    
    //Your method and property declarations
    

    EDIT:

    Let’s say I put the - (void)textViewDidChange:(UITextView *)textView code in a file called MyClass.m. The file MyClass.m would then look like this:

    @implementation MyClass
    
    - (void)textViewDidChange:(UITextView *)textView {
    
        //All the above code goes here
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        //INCLUDE THESE LINES
        Sum_TextField.delegate = self;
        Answer_TextField.delegate = self;
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    @end
    

    In the header file (MyClass.h), I would put this:

    @interface MyClass : UIViewController <UITextViewDelegate> 
    
    //Note: you don't declare - (void)textViewDidChange:(UITextView *)textView in the header file because you are implementing
    //a protocol method.
    
    //MAKE SURE SUM_TEXTFIELD AND ANSWER_TEXTFIELD ARE UITEXTVIEWS NOT UITEXTFIELDS
    @property (strong, nonatomic) IBOutlet UITextView *Sum_TextField;
    @property (strong, nonatomic) IBOutlet UITextView *Answer_TextField;
    
    @end
    

    Hope this helps!

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

Sidebar

Related Questions

For a school assignment, we have to make a Usecase diagram. But the documentation
For a school assignment me and a friend have been working on rendering a
I have this school assignment that I've been working on and am totally stumped
For a school assignment I have to make a connection to a database from
For a school assignment we have to make a client server chat program in
We have a school assignment and we were told that all numbers end after
For a school assignment I have to create a C++ program that will create
Hello is have a question for a school assignment i need to : Read
I have to implement a search algorithm for a school assignment. Right now, i'm
I have an assignment for school, and I'm not sure how the teacher wants

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.