Date picker with minutes and seconds - ios

I'm new to Swift and fairly new to programming in general. I'm making a basic countdown timer app and want to use a date picker to select the duration of the countdown. I have a label which is a concatenation of a timeMin variable and a timeSec variable, seperated by a ":" string.
When the date picker's mode is set to countdown timer, it can only do hours and minutes. Is there any way I could change this to minutes and seconds? The text displayed on the date picker should be minutes and seconds too, rather than hours and minutes.
So if my label starts off as 02:00, using the date picker and selecting 4 in minutes and 35 in seconds should simply result in the label changing to 04:35.
Thanks for taking the time to help.

This is not possible with UIDatePicker, If you want to implement this, then you have to create custom datepicker by using UIPickerView. You have to take 2 components in UIPickerView, one for minutes and one for seconds. And supply the values(with appropriate interval) from titleForRow: ... method of UIPickerViewDatasource.

Related

How to set custom date display on UIDatePicker?

I have added a UIDatePicker from storyboard. By default picker shows me the date format as (October - 26 - 2017). But i want the format to be dispayed as (26 - 10 - 2017 ).I am not able to display date in this format on UIDatePicker.Please tell me how can i do this?
You can't do this.
From Apple's documentation for: UIKit > Views and Controls > UIDatePicker
Appearance
The appearance of UIDatePicker is not customizable.
The only thing Apple allows you to change is the date picker mode, which is not what you want. To change the layout to "dd-mm-yyyy", you will need build your own customized picker.
The way I'd suggest going about this, is instead of using UiDatePicker, to use UIPicker. Then, create and assign to that picker a unique class, which inherits from UIPickerView. This way you can customize it exactly how you want. Here is a helpful link for how to get all dates between a range (which is how UIDatePicker() is populated) - Swift: Print all dates between two NSDate()

How to implement two default cells of tableview one after the another with animation with time duration?

I have succesfully loaded these two default cells of tableview. But my problem is I have to animate these two cells.For example one custom cell will load first then after 1 minutes another cell will load.Now new loaded cell of tableview appear on the top.
I have use cell will display method for animation but nothing happened.How to do this type of animation with time duration.
There are a lot of libraries out there for animations like this , also you can try with core graphics animation which will be a little time consuming.
for waiting 1 minute use the timer
or
use UNIX function sleep
sleep(4)
or
Swift 3
With GCD:
let delayInSeconds = 4.0
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delayInSeconds) {
// here code perfomed with delay
}

Objective C: how to get an integer from uitextfield to work as a timer

I'm creating my first app with Objective C, one function with let the user to provide an amount (in numbers) with 2 decimal places into a UITextField. I would like that to be processed using a UIButton to appear in a UILabel which runs according to a timer.
I.E. if the user inputs 5.60 into the UITextField, when the UIButton is pressed, this amount should transfer to the UILabel which acts as timer and counts to 5.60 every 60 seconds.
The counter should go up by 0.01 to reach 5.60 in 60 seconds.
This is all on one ViewController.
Thanks in advance if anyone sees this and has the time to help!

Resume NSTimer when view loads back

So I have a view that has a timer on it. So when you press "start" the NSTimer starts updating the UILabel with the time elapsed. Now when you press back to previous view, I store the current duration of the timer and when I load this view back I want to start the NSTimer again but this time I want to display the time that has passed.
So for example,
Start timer: 0:0:0
Pressed back at: 0:0:10
When I come back to the view after 30 seconds, right now NSTimer starts back from: 0:0:10 when it should be at 0:0:40
This is how I am calculating the resume time:
NSDate *resumeDate = [today dateByAddingTimeInterval:interval];
Any idea on how to get the correct timestamp?
An NSTimer cannot be "started again". Once you start the timer all you can do is let it run or stop it.
You have to create a new NSTimer object with the new timestamp.
As for how to add to a timestamp, the NSTimeInterval data type is an alias for a standard C double value. So you can just do this:
interval += 4.2 // add 4.2 seconds to the interval
You can not pause a timer but to stop it. So if you want to "Resume NSTimer", you can only create a new timer the same as your previous timer and let it run.

Take current Countdown Timer value

I am using a UIDatePicker in the countdown timer mode. I want to take the current set time on the uidatepicker in seconds and put it in an integer value? How is this done?
The UIDatePicker has a property called countDownDuration so you should be able to use
int seconds = (int)datePicker.countDownDuration;
Edit: to address concern in the comment, make sure to manually set either the countDownDuration or the time of the datePicker in order to get a "whole-minute" value. For instance, in viewDidLoad you could set:
datePicker.countDownDuration = 60.0f;
and then the default-selected time duration in your countdown would be exactly 0 hours, 1 minute. Otherwise, by default the date picker will use the current date/time and setting your countdown timer could result in countDownDuration being up to +59 seconds (e.g. 1 minute could ready anywhere from 60-119, 2 minutes from 120-179, etc) based on the time when you run your app.

Resources