我的應用程序中有一本字典。您在列表視圖中選擇您的信件。單擊它時,它會爲所有字母打開相同的ViewController,但它會根據它們的編號位置確定從列表視圖中選擇哪個字母。他們都工作,除了兩個。這兩個詞的共同之處在於它們是兩個最長的字母詞典部分。這似乎是問題,雖然我不知道如何解決它,以便他們將再次顯示。這是代碼在加載時的樣子。在Xcode 5中編譯應用程序時不再顯示文本
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
int scrollHeight;
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
if([selected intValue] == 0){
self.title = @"A";
content.text = @"A definitions go here. This string works";
}
else if([selected intValue] == 1){
self.title = @"B";
content.text = @"B definitions go here. This string (along with 'S') does not display";
}
else if([selected intValue] == 2){
self.title = @"C";
content.text = @"C definitions go here. This string works";
}
scrollHeight = 12500;
content.lineBreakMode = UILineBreakModeWordWrap;
CGSize expectedLabelSize = [content.text sizeWithFont:content.font
constrainedToSize:content.frame.size
lineBreakMode:UILineBreakModeWordWrap];
CGRect newFrame = content.frame;
newFrame.size.height = expectedLabelSize.height;
content.frame = newFrame;
content.numberOfLines = 0;
[content sizeToFit];
scrollView.contentSize = CGSizeMake(320, scrollHeight);
[mainView addSubview:scrollView];
}
就像我說的。除了最長的兩個之外,它對所有的人都是完美的。我已經更新了應用程序,並在舊版Xcode 4.something上進行了測試。然後這些工作正常。直到我決定更新到Xcode 5因爲gdb問題,它突然中斷,不再顯示任何文本。
那麼你在context.text上設置的字符串不會顯示?如果在if中手動設置相同的字符串(長度相同),它是否工作?你有沒有嘗試過在你的UILabel上調用layoutIfNeeded或setNeedsDisplay?改變它後,你確定你的內容高度不是0嗎? – Olshansk
@Olshansk是的字符串不顯示在那個特定的一個。這個完全相同的代碼用於所有其他字母,並且在同一個.m上。 if([selected intValue] == 1)及其包含的所有內容與content.text中其他字母的內容相同。如果([selected intValue] == 2),它們每個都被分隔,等等。字母B和S的兩個最長文本字符串不工作,而其他一切正常工作。我會看看你提到的其他事情。內容的高度是因爲它是設置,並不會變爲0. – steven