Iphone XCode 我的倒计时不再显示动画
嘿伙计们另一个问题!
我想再次声明,我对此很陌生,因此我对 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";
}
}
非常感谢大家的帮助,我真的希望有人可以帮助我!
谢谢你们, Phil
好的,这是主屏幕的整个 .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
,请参阅我在 ViewDidAppear
上有一个 (BOOL) 动画,但我不知道如何将其添加到 if 语句中(Noob )
Hey Guys another question!
Once again I would like to state that i am new to this and therefore my ability to understand the language Objective C and the Xcode application is limited! So Your help really and truly is appreciated greatly!
I built a countdown app that shows when a radio station is going to be going live, the countdown worked perfectly and updated in realtime once a second, then I inserted it into an "If-Statement" so that when the day of the station launch arrives the countdown disappears, but now my countdown does not update in realtime it just sits static.
The following is my code:
- (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";
}
}
Guys any help is greatly appreciated and I really hope someone out there can help me!
Thanks guys,
Phil
ok here is the code for the whole .M file of the home screen
#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
See I had a (BOOL)animated on the ViewDidAppear
but I am not sure how to add this into the if-statement (Noob)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现 NSLog() 对于追踪未正确触发条件的事物非常有用。
紧接在
if()
之前,执行:然后查看控制台上显示的内容。
我搞砸了这类事情的一个地方是以错误的顺序测试这些值,所以我期望的负值是正值,反之亦然。
此外,您几乎泄漏了在该代码中分配的所有内容。请返回并<code>释放您
分配
的所有内容!I find NSLog() invaluable for tracking down things that don't fire conditionals correctly.
Immediately before your
if()
, go:And then look and see what you get on the console.
One place I've messed up this sort of thing is to test the values in the wrong order, so what I expect to be negative is positive and vice versa.
Also, you're leaking pretty much everything you allocate in that code. Go back through and
release
everything youalloc
please!