Эй, ребята, еще вопрос!
Еще раз я хотел бы заявить, что я новичок в этом, и поэтому моя способность понимать язык Objective C и приложение XCode ограничена! Так что Ваша помощь действительно и очень ценится!
Я создал приложение обратного отсчета, которое показывает, когда радиостанция будет запущена, обратный отсчет работал отлично и обновлялся в режиме реального времени раз в секунду, затем я вставил его в «If-Statement», чтобы, когда запуск станции прибывает, отсчет исчезает, но теперь мой отсчет не обновляется в режиме реального времени, он просто остается статичным.
Вот мой код:
- (void)viewDidAppear:(BOOL)animated {
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *launchDay = [[NSString alloc] initWithString:@"11/26/2010 11:59:59"];
NSDate *currentDate = [dateformatter dateFromString:launchDay];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:today toDate:currentDate options:0];
if ([today timeIntervalSinceDate:currentDate] <= 0 ){
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", components.day, components.hour, components.minute, components.second ];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[self updateLabel];
days.text = @"Days";
hours.text = @"Hours";
mins.text = @"Mins";
secs.text = @"Secs";
until.text = @"Until XtremeFM Launch!";
}
else {
countdownLabel.text =@"XtremeFM is LIVE";
}
}
Ребята, любая помощь очень ценится, и я действительно надеюсь, что кто-то там может мне помочь!
Спасибо, ребята,
Фил
Хорошо, вот код всего файла .M домашнего экрана
#import "XtremeFMViewController.h"
@implementation XtremeFMViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
@synthesize countdownLabel, today, timer, todayDate, days, hours, mins, secs, until;
-(void)updateLabel {
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
//NSString *launchDay = [[NSString alloc] initWithString:@"11/26/2010 11:59:59"];
//NSDate *currentDate = [dateformatter dateFromString:launchDay];
//NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
//NSDateComponents *components = [gregorian components:unitFlags fromDate:today toDate:currentDate options:0];
}
- (void)viewDidAppear:(BOOL)animated {
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *fathersDay = [[NSString alloc] initWithString:@"11/26/2010 11:59:59"];
NSDate *currentDate = [dateformatter dateFromString:fathersDay];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:today toDate:currentDate options:0];
if ([today timeIntervalSinceDate:currentDate] <= 0 ){
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", components.day, components.hour, components.minute, components.second ];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[self updateLabel];
days.text = @"Days";
hours.text = @"Hours";
mins.text = @"Mins";
secs.text = @"Secs";
until.text = @"Until XtremeFM Launch!";
}
else {
countdownLabel.text =@"XtremeFM is LIVE";
}
}
- (IBAction)watchLive {
self.today = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *launchDay = [[NSString alloc] initWithString:@"11/26/2010 11:59:00"];
NSDate *currentDate = [dateformatter dateFromString:launchDay];
//NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
//NSDateComponents *components = [gregorian components:unitFlags fromDate:today toDate:currentDate options:0];
//countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", components.day, components.hour, components.minute, components.second ];
if ([today timeIntervalSinceDate:currentDate] >= 0 ){
NSString *webpage = @"http://xphiltestpagex.is.livestream-api.com/livestreamiphone/philtestpage/playlist.m3u8";
NSURL *nswebpage = [NSURL URLWithString:webpage];
NSURLRequest *nsurl = [NSURLRequest requestWithURL:nswebpage];
[webView loadRequest:nsurl];
}
else {
UIAlertView*alert = [[UIAlertView alloc] initWithTitle:@"Coming Soon" message:@"Feed goes live Friday 26th November 12:00pm" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
-(IBAction)requestsPage {
RequestsPageViewController *move = [[RequestsPageViewController alloc]initWithNibName:nil bundle:nil];
move.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:move animated:YES];
[move release];
}
-(IBAction)twitterButton {
RequestsPageViewController *move = [[RequestsPageViewController alloc]initWithNibName:nil bundle:nil];
move.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:move animated:YES];
[move release];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Видите ли, у меня был анимирован (BOOL) ViewDidAppear
, но я не уверен, как добавить это в оператор if (Noob)