简体   繁体   English

Iphone XCode我的倒数不再动画

[英]Iphone XCode My Countdown no longer Animates

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! 我想再次声明,我是新手,因此我对目标Objective C和Xcode应用程序语言的理解能力受到限制! 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. 我构建了一个倒计时应用程序,该程序可以显示广播电台何时开始直播,倒数计时工作正常并每秒进行一次实时更新,然后将其插入“ If-Statement”中,以便当电台开播当天到了倒数计时就消失了,但是现在我的倒计时并没有实时更新,它只是静止的。

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 好的,这是主屏幕的整个.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

See I had a (BOOL)animated on the ViewDidAppear but I am not sure how to add this into the if-statement (Noob) 看到我在ViewDidAppear上设置了动画(BOOL),但是我不确定如何将其添加到if语句中(Noob)

I find NSLog() invaluable for tracking down things that don't fire conditionals correctly. 我发现NSLog()对于跟踪无法正确触发条件的事情非常有用。

Immediately before your if() , go: if()之前,立即执行:

NSLog(@"%d", [today timeIntervalSinceDate:currentDate]);

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 you alloc please! 返回并releasealloc所有内容!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM