Iphone XCode我的倒计时不再动画

Iphone XCode我的倒计时不再动画,iphone,xcode,sdk,countdown,Iphone,Xcode,Sdk,Countdown,嘿,伙计们,还有一个问题 我想再次声明,我是新手,因此我理解语言Objective C和Xcode应用程序的能力有限!非常感谢您的帮助 我开发了一个倒计时应用程序,它显示电台何时上线,倒计时工作正常,每秒实时更新一次,然后我将它插入If语句中,这样当电台上线的那一天到来时,倒计时就消失了,但现在我的倒计时没有实时更新,它只是静止不动 以下是我的代码: - (void)viewDidAppear:(BOOL)animated { self.today = [NSDate date

嘿,伙计们,还有一个问题

我想再次声明,我是新手,因此我理解语言Objective C和Xcode应用程序的能力有限!非常感谢您的帮助

我开发了一个倒计时应用程序,它显示电台何时上线,倒计时工作正常,每秒实时更新一次,然后我将它插入If语句中,这样当电台上线的那一天到来时,倒计时就消失了,但现在我的倒计时没有实时更新,它只是静止不动

以下是我的代码:

- (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

请看,我在ViewDidDisplay上有一个BOOLanimated,但我不确定如何将其添加到if语句Noob中。我发现NSLog对于跟踪未正确触发条件语句的情况非常有用

在您的if之前,请执行以下操作:

然后看看你在控制台上看到了什么

我搞砸了这类事情的一个地方是以错误的顺序测试值,所以我期望的是负的是正的,反之亦然


而且,您正在泄漏代码中分配的几乎所有内容。请返回并释放所有您分配的内容

我发现NSLog对于追踪那些不能正确触发条件语句的东西非常有用

在您的if之前,请执行以下操作:

然后看看你在控制台上看到了什么

我搞砸了这类事情的一个地方是以错误的顺序测试值,所以我期望的是负的是正的,反之亦然


而且,您正在泄漏代码中分配的几乎所有内容。请返回并释放所有您分配的内容

包括updateLabel的代码。您只需设置一次标签文本,似乎希望标签每秒更新一次。请修复格式设置。似乎您已将设置标签文本的代码(现在已注释掉)移动到ViewDidDisplay,该代码仅在显示整个视图时调用。我认为您需要花一些时间阅读以下内容,包括updateLabel的代码。您只需设置一次标签文本,似乎希望标签每秒更新一次。请修复格式设置。似乎您已将设置标签文本的代码(现在已注释掉)移动到ViewDidDisplay,该代码仅在显示整个视图时调用。我想你需要花一些时间阅读以下内容,将其添加到应用程序中并在控制台中运行,但没有向任何类型的日志中添加任何内容,我以前运行过NSLogs,所以我知道它们应该如何显示,但这没有显示任何内容。你知道吗,我说使用%d,它应该是%f,因为NSTimeInterval是双精度的。我很惊讶你没有找到一个糟糕的执行官。。。用一个%f试试,看看它说的是否合理。将它添加到应用程序并在控制台中运行,但没有向任何类型的日志添加任何内容,我以前运行过NSLogs,所以我知道它们应该如何显示,但这没有显示任何内容。你知道吗,我说使用%d,它应该是%f,因为NSTimeInterval是双精度的。我很惊讶你没有找到一个糟糕的执行官。。。用%f试试看,看它说的是否合理。
NSLog(@"%d", [today timeIntervalSinceDate:currentDate]);