Slight delay on a label, testing on iphone

Discussion in 'iOS Programming' started by SunnyLi, Oct 7, 2010.

  1. SunnyLi Guest

    Joined:
    Oct 7, 2010
    #1
    Hi Guys,

    New here just wondered if you could help, my application runs fine in the simulator. But when i put it on my phone theres a slight delay on the text thats in the label ie it loads up about a second later.

    Is there any way around this at all?

    I appreciate your answers....


    SunnyLi
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    What code is running when the button is clicked? Perhaps it's blocking the UI.
     
  3. SunnyLi thread starter Guest

    Joined:
    Oct 7, 2010
    #3
    Ive put the label in its own method like so:

    Code:
    -(void)updateLabel{
    	self.datestart = [NSDate date];
    	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    	int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    	NSDateComponents *components = [gregorian components:unitFlags fromDate:datestart toDate:xmasDate options:0];
    	countdown.text = [NSString stringWithFormat:@"%02d "" %02d "" "" %02d "" %02d", components.day, components.hour, components.minute, components.second ];
    	countdown.textColor = [UIColor blackColor];
    	
    }
    But i just notice the music is the same and thats in the viewdidload.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Ah, sorry. Misread your OP. There's no button at all.

    So, you're updating a label in a countdown loop of some kind. How are you calling updateLabel and how are you handling the loop? You say you also have music. How is that being played?
     
  5. SunnyLi thread starter Guest

    Joined:
    Oct 7, 2010
    #5
    The updatelabel is called from a timer in the viewdidload method

    Code:
    NSDate *today = [NSDate date];
    	NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    	NSDateComponents *yearComp = [gregorian components:(NSYearCalendarUnit) fromDate:today];
    	NSInteger year = [yearComp year];
    	
    	
    	NSDateComponents *comps = [[NSDateComponents alloc] init];
    	[comps setYear:year];
    	[comps setMonth:12];
    	[comps setDay:25];
    	[comps setHour:00];
    	[comps setMinute:00];
    	[comps setSecond:00];
    	self.xmasDate = [gregorian dateFromComponents:comps];
    	[comps release];
    	
    	[B]self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];	[/B]
    
    the background music in here aswell

    ---edit---
    i think i found the problem


    scheduledTimerWithTimeInterval:(1.0)

    but the musics slightly off still...
    Code:
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"good" ofType:@"mp3"];
    	NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    	theAudio= [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
    	
    	[theAudio play];
    	theAudio.numberOfLoops = -1;
    	
    	[filePath release];
    	[fileURL release];
    	
    	[super viewDidLoad];
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Slightly off? Please elaborate.
     
  7. SunnyLi thread starter Guest

    Joined:
    Oct 7, 2010
    #7
    Theres a few seconds delay after the views loaded.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Before it starts playing?
     
  9. SunnyLi thread starter Guest

    Joined:
    Oct 7, 2010
    #9
    yeh as soon as the splash screen goes.
     
  10. SunnyLi thread starter Guest

    Joined:
    Oct 7, 2010
    #11
    Cheers,

    Realised i made a school boy error on that one, ive just cut the song down by a few seconds works fine now :)

    thanks for the help.
     

Share This Page