I’ve got an issue with a label showing a String.
So, basically, I’ve got a function - (void) didFinishUpdatesSuccessfully. If this function is being called it means that an action has been completed successfully. It creates a time stamp and stores it to NSUserDefaults. All this works like a charme..
Here’s the function:
- (void) didFinishUpdatesSuccessfully {
// Create formatted date string
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd/MM/YYYY - hh:mm:ss a"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
NSMutableString* lastUpdated;
lastUpdated = [[NSMutableString stringWithFormat:@"%@",dateString] retain];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:lastUpdated forKey:@"lastUpdated"];
[defaults synchronize];
//--- Alert dialog
NSString *title;
title = @"All the latest hotspots have now been saved!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: title
message: lastUpdated
delegate: nil
cancelButtonTitle: [FileUtils appResourceForKey:@"HOTSPOT_GENERAL_BUTTON_TITLE_OK"]
otherButtonTitles: nil];
// ------------------------
//Create label
UILabel *UpDLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 205, 250, 100)];
UpDLabel.backgroundColor = [UIColor clearColor]; // [UIColor brownColor];
UpDLabel.font = [UIFont fontWithName:@"Helvetica" size: 11.0];
UpDLabel.shadowColor = [UIColor whiteColor];
UpDLabel.shadowOffset = CGSizeMake(1,1);
UpDLabel.textColor = [UIColor blackColor];
UpDLabel.textAlignment = UITextAlignmentRight; // UITextAlignmentCenter, UITextAlignmentLeft
UpDLabel.lineBreakMode = UILineBreakModeWordWrap;
NSString *lupdate = [NSString stringWithFormat: @"Last Update: %@", lastUpdated];
UpDLabel.text = lupdate;
[self.view addSubview:UpDLabel];
[UpDLabel release];
// ------------------------
[dateFormatter release];
[lastUpdated release];
[alert show];
[alert release];
//--- remove indicator view
[self indicatorViewShow:NO];
}
The label with the date string is being displayed. It overrides itself but seems to keep the previous string so it actualy looks like it just adds another layer on top of the previous one. Or in other words, if I perform the - (void) didFinishUpdatesSuccessfully 3 times it will show 3 date strings on top of each other which looks screwed…
What am I doing wrong?
Cheers
Jan
You are recreating and re-adding the UpDLabel to your view every time the didFinishUpdatesSuccesfully method is called.
Instead make UpDLabel a property of your class:
And in your code in the didFinishUpdatesSuccesfully do: