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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:00:37+00:00 2026-05-18T02:00:37+00:00

In my iPhone project, I have a common date editing view which features a

  • 0

In my iPhone project, I have a common “date editing” view which features a UIDatePicker. I would like to use this view to update one NSDate property based on the way it’s called.

The way I thought about achieving that is to have an NSDate property called CurrentlyEditedDate which I set to point to the correct NSDate property I could like to edit. But I don’t know how to do that.

Let’s say I have 2 NSDate properties defined:

@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic, retain) NSDate *endDate;

When I launch my view I would like to do the following:

CurrentlyEditedDate = startDate

Or the following based on the caller:

CurrentlyEditedDate = endDate

So that my view can edit any NSDate object. However I don’t know how to define or assign the CurrentlyEditedDate property. Nor do I know how to set it up from the view to a new NSDate value.

  • 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-18T02:00:38+00:00Added an answer on May 18, 2026 at 2:00 am

    I think actually the best solution here would be to implement a delegate protocol. It looks a little thornier, but it won’t be as fragile as trying to store the variable reference.

    Here’s what you need to do:

    First, declare the protocol so that other classes know what to implement in order to receive your delegate messages. Also, create a .delegate property so that other objects can tell your date picker that they want to get those messages:

    // MyDatePicker.h
    #import <Cocoa/Cocoa.h>
    
    @class MyDatePicker;
    @protocol MyDatePickerDelegate <NSObject>
    - (void)myDatePicker:(MyDatePicker *)datePicker didChangeDate:(NSDate *)date;
    @end
    
    @interface MyDatePickerViewController : UIViewController {
        id<MyDatePickerDelegate> delegate;
    }
    
    @property (nonatomic, assign) id<MyDatePickerDelegate> delegate;
    
    @end
    

    Then when you get a new date from your picker, you just need to check to see if you have a delegate, and that they have implemented your method. If they have, just go ahead and tell them about the new date:

    // MyDatePickerViewController.m
    #import "MyDatePickerViewController.h"
    
    @implementation MyDatePickerViewController
    
    - (void)changedDate:(NSDate *)newDate {
        if ([delegate respondsToSelector:@selector(myDatePicker:didChangeDate:)]) {
            [delegate myDatePicker:self didChangeDate:newDate];
        }
    }
    
    @end
    

    Then, in your class where you want to receive the date info you might do something like this:

    - (void)createDatePicker {
        MyDatePicker *datePicker = [[MyDatePicker alloc] init];
        datePicker.delegate = self;
    }
    
    - (void)myDatePicker:(MyDatePicker *)datePicker didChangeDate:(NSDate *)date {
    
        if (startTimeOrSomething) {
            self.startDate = date;
        } else {
            self.endDate = date;
        }
    }
    

    I just typed that without compiling, but it should be correct. This may seem like a lot of work, but it will very quickly become second nature, and is a much more robust way to handle these kinds of situations.

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

Sidebar

Related Questions

I am working on an iPhone project which I have translated to two languages
In my current iPhone project I need to decrypt zip files which have been
I'm wondering if it's possible to make the iPhone app project I have into
If I have a project that was written for iphone and a project written
In my iPhone project, I was told to use the username and password property
I've been working on an iPhone project with iOS 4.0. I just downloaded Xcode
I've got an XCode iPHone project setup with the following: My App Delegate creates
I'm working on an iphone project where I need both a horizontal and a
From the Game Kit Programming Guide ... Multiplayer allows players interested in playing an

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.