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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:57:01+00:00 2026-05-25T19:57:01+00:00

So basically in this code I placed below there is a couple things I

  • 0

So basically in this code I placed below there is a couple things I would like to accomplish. 1) In that first one I would like the Text Field to close after done is pressed, but it is not doing so. (Found that code on other forums). 2)On that first button when it is pressed down I would like it to send a time to be saved for when the button is released. 3) On release of that button I would like it to calculate the time between the two times along with some other calculations later.

Problem that I am mainly getting here is the error from the NSTimeInterval. It keeps telling me that NSTimeInterval is incompatiable with type NSTimeInterval. So a double is incompatible with a double??? (I have also tried it with NSTimeInterval *timePassed in the .h and just trying to set timePassed = to it and it doesn’t work either. Similar error happens.

#import "MphViewController.h"

@implementation MphViewController
@synthesize speed, distance;

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(IBAction)triggerDown:(id)sender{

    timeStart = [NSDate date];

}

-(IBAction)triggerUp:(id)sender{
    NSInteger *dist;
    NSString *display;
    NSTimeInterval *timePassed = [timeStart timeIntervalSinceNow];
    if ([distance.text length]== 0) {
        display = @"Please enter a distance";
    }
    else{
        dist = atoi(distance.text);
        display = [[NSString alloc] initWithFormat:@"%d MPH",dist];
    }
    speed.text = display;


    [display release];
}

Also if you have a chance to glance at the else statement. I’m not sure if that will work (seeing is after I enter a distance I still cant get rid of the numberpad). Id like to pass mph once it is calculated into that to be displayed on the screen. Very confused with how parsing is done on obj c. Anyways thanks for any and all help.

As for the textField part. My textField that it is assigned to is distance. Should that Bool be written differently to have distance in it or is that just the way it is supposed to be written?

  • 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-25T19:57:01+00:00Added an answer on May 25, 2026 at 7:57 pm

    You are denoting primitive types as pointers where they do not need to be. Remove the star (*) from the NSInteger and NSTimerIntervaldeclaration. The if check looks fine but instead of atoi just use:

    dist = [distance.text integerValue];
    

    Edit:
    Notice a couple of memory management issues.

    1 . Make sure you properly retain/release the date then later release it in dealloc.

    -(IBAction)triggerDown:(id)sender{
        [timeStart release];
        timeStart = [[NSDate alloc] init];
    }
    

    2 . Your if statement will result in trying to release an NSString literal which likely will not crash but is incorrect memory management. Just use an autoreleased string and remove the [display release];

    ...
    else{
            dist = [distance.text integerValue];
            display = [NSString stringWithFormat:@"%d MPH",dist];
        }
        speed.text = display;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I was writing some code today that basically looks like this: string returnString
Basically this code below returns the right information, but I need to add the
This code basically translates characters based on position in one string to the character
Basically i am having problems with my code - this is homework so would
So basically this code was working fine before. I had some computer issues and
I am using this code to alter the title of an image. Basically it
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I recently came across this in some code - basically someone trying to create
I'm trying to modify the code from this script . Basically I'm trying to
This isn't a code question for once, but it definitely has me confused. Basically,

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.