0
在我的應用我創建一個臨時對象,例如以下列方式標籤:
UILabel *tempLabel = [ [UILabel alloc] initWithFrame: CGRectMake(100, 5, 200, 30)];
tempLabel.backgroundColor = [UIColor colorWithRed: 1.0f green: 1.0f blue: 1.0f alpha: 0.0f];
tempLabel.text = [ [WordsDatabase sharedWordsDatabase] dbName];
[ [self view] addSubview: tempLabel];
[tempLabel release];
這段代碼被稱爲從viewWillAppear方法。
當視圖本身第一次被調用時,一切都很好。但第二次,新標籤似乎與舊標籤重疊。
爲了使這種效果消失,是否有任何步驟需要採取? 要添加到viewWillDisappear方法的東西?
我試圖將標籤聲明添加到類接口中,並在viewWillDisappear方法中調用[label removeFromSuperview]。在這種情況下,一切都很好。 有沒有辦法做到這一點,而不存儲對標籤的引用?
預先感謝您。