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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:24+00:00 2026-05-26T20:00:24+00:00

In my app, I have a UITableView with 3 cells. If the user selects

  • 0

In my app, I have a UITableView with 3 cells. If the user selects one of the top two cells, they can change the value using a UIDatePicker to make it say for example “November 11, 2011”.

Is there a way to subtract the dates from the first cell to the second one?

Like the user inputs “November 11, 2011” into the first cell, and in the second cell inputs “November 11, 2012”, how can I get the 3rd cell to say, “1”, or “1 year”?

My code is –

.h

IBOutlet UIDatePicker *datePicker;
    UITableView *products;
    NSMutableArray *productsInfo, *extras;
    NSDateFormatter *dateFormatter;
}

@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic,retain) IBOutlet UITableView *products;
@property (nonatomic,retain) NSDateFormatter *dateFormatter;;
-(IBAction)DateChanged:(id)sender;

.m –

@implementation PushedViewController

@synthesize datePicker;
@synthesize products,dateFormatter;

-(IBAction)DateChanged:(id)sender{
    NSIndexPath *indexPath = [self.products indexPathForSelectedRow];
    UITableViewCell *cell = [self.products cellForRowAtIndexPath:indexPath];
    cell.detailTextLabel.text = [self.dateFormatter stringFromDate:self.datePicker.date];
}

- (void)viewDidLoad
{

    self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [self.dateFormatter setDateStyle:NSDateFormatterLongStyle];
    productsInfo = [[NSMutableArray alloc]init];
    extras = [[NSMutableArray alloc]init];
    [extras addObject:@"Time Left"];
    [productsInfo addObject:@"Date Bought"];
    [productsInfo addObject:@"Date Ending"];

    //product.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"MakeText"];
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    if (section==0){
        return [productsInfo count];
    }
    else{
        return [extras count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    if (indexPath.section==0){
        cell.textLabel.text = [productsInfo objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [self.dateFormatter stringFromDate:[NSDate date]];
    }
    else {
        cell.textLabel.text = @"Time Left";
        cell.detailTextLabel.text = @"8";
    }


    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *targetCell = [tableView cellForRowAtIndexPath:indexPath];

}

@end
  • 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-26T20:00:25+00:00Added an answer on May 26, 2026 at 8:00 pm

    In order to do this, you will have to store each of those two dates selected in the cells in instance variable to reference in the third cell. After the third cell has both dates that it needs to perform the calculation, things get a little more difficult. Using two NSDates, you are wanting to output a time interval in human words to the user. There are not any factory methods for doing this, but a friend of mine has created a helpful class, TTTTimeIntervalFormatter that will do just this.

    You can use it like so:

    NSDate *dateFromFirstDatePicker = [datePicker1 date];
    NSDate *dateFromSecondDatePicker = [datePicker2 date];
    TTTTimeIntervalFormatter *timeIntervalFormatter = [[TTTTimeIntervalFormatter alloc] init];
    
    NSString *timeInterval = [timeIntervalFormatter stringForTimeInterval:[dateFromFirstDatePicker timeIntervalSinceDate:dateFromSecondDatePicker]];
    
    //other examples
    [timeIntervalFormatter stringForTimeInterval:0]; // "just now"
    [timeIntervalFormatter stringForTimeInterval:100]; // "1 minute ago"
    [timeIntervalFormatter stringForTimeInterval:8000]; // "2 hours ago"
    
    [timeIntervalFormatter release];
    

    Then you can update the third cell using the standard UITableViewDataSource method cellForRowAtIndexPath: to update the contents of the cell.

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

Sidebar

Related Questions

I have an app, where there's one UIWebView and a UITableView. I don't want
In an app I'm working on, I have a plain style UITableView that can
In my app I have a set number of cells in a UITableView, 10,
I have a app that will populate a UITableView after the user takes a
In my Universal App I have a long UITableView with custom cells..and for some
On my iphone app, I have a UITableView in edit mode, containing custom UITableViewCell.
i have an UITableView in my app and i have to load some images
I have an app wherein the datasource for a UITableView updates by a background
I have a working UITableView filled with some options for my app, and i
I have set up a UITableView-based app, which has a .plist for holding the

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.