Skip to content

Tab Bar Controller in Objective-C – Example (Video)

Learn how to work with a Tab Bar Controller in Objective-C and manage each of its views independently, with a video tutorial and example code.

To download the project for this post, click HERE.

In this tutorial you will see how to work with a Tab Bar Controller, and how to work independently with each of the views that make up this Tab Bar Controller. In this video tutorial we will build the following app. The third view of this tutorial corresponds to the following tutorial: NSTimer in Objective-C -Example- (Video).

tabBar Controller jarroba

Here is the video of the finished project:

Below are the methods we used to get the date and time in the example app:

Code to get the current date:

// Get today's date
NSDate *hoy = [NSDate dateWithTimeIntervalSinceNow:0];

// Format it and store it in the NSString fecha so we can print it
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MMMM-yyy"];
NSString *fecha = [dateFormat stringFromDate:hoy];

Code to get the time. To make it update every second, you should use a timer that calls this method every half second (more or less):

-(void) setHora{
    // Get today's date
    NSDate *hoy = [NSDate dateWithTimeIntervalSinceNow:0];

    // Calculate hours, minutes and seconds
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *dateComponents = [gregorian components:(NSHourCalendarUnit  | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:hoy];
    NSInteger horas = [dateComponents hour];
    NSInteger minutos = [dateComponents minute];
    NSInteger segundos2 = [dateComponents second];

    NSString *hora = [NSString stringWithFormat:@"%02i:%02i:%02i",horas, minutos, segundos2];
}

“Tab Bar Controller in Objective-C – Example (Video)” by Ricardo Moya at jarroba.com, licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Registered at Safe Creative.

Ricardo Moya

I work in Machine Learning and Big Data. I like learning new technologies and explaining them as clearly as I can on this site.

You may also like

Comments

Leave a comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.