我遇到了顯示字符串的標籤問題。字符串/標籤問題
所以,基本上,我有一個功能- (void) didFinishUpdatesSuccessfully
。如果這個函數被調用,這意味着一個操作已經成功完成。它創建一個時間戳並將其存儲到NSUserDefaults。這一切就像一個風情萬種.. 這裏的功能:
- (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];
}
正在顯示的日期字符串的標籤。它覆蓋了自己,但似乎保留了以前的字符串,所以它看起來好像只是在前一個字符串上添加了另一個圖層。或者換句話說,如果我執行3次- (void) didFinishUpdatesSuccessfully
它會顯示3個日期字符串在彼此之上看起來被擰緊...
我在做什麼錯了?
乾杯 月
這完美的作品。非常感謝。 – Jan
注意:我已將代碼添加到我的viewDidLoad中。現在完美運作。再次感謝。 – Jan