2013-01-24 120 views
0

我只想在UIAlertView上顯示一些文本,但如果文本長度大於允許的大小,它顯示"Null"字符串。UIAlertView最大文本長度

我非常肯定文本不會比屏幕大(大約有一半以上),所以我不想讓這個實現ScrollView變得複雜。

我跟着problem in changing size of uialertview改變AlertView大小,但它不能正常工作,還產生一些怪異的視覺效果。

我試過這第三部分組件https://github.com/inamiy/YIPopupTextView,我甚至無法通過編譯。 (已經將4個文件導入到項目中)。我不知道爲什麼。

所以,實際上我只是想增加允許在AlertView上顯示的文字大小。任何想法?

+0

你想要顯示的文本就像一個段落? –

+1

使你自己的警報視圖更容易 – amar

回答

3

我寫了一個很小的測試程序。這是我加入到單一視圖應用程序模板的唯一的事情:

- (void)viewDidAppear:(BOOL)animated { 
    NSMutableString *message = [[NSMutableString alloc] init]; 
    while (message.length < 100000) { 
     [message appendString:@"Hello, world! "]; 
    } 
    [message appendString:@"This is the end."]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test" message:message delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil]; 
    [alert show]; 
} 

這正常上運行iOS 5.0的iPhone模擬器,並在我的iPhone 5運行iOS 6.0.2。顯示所有文本(在可滾動的文本視圖中)。

您的問題可能不是文字的大小。

+0

雅,那是我的錯。我做的另一個錯誤是我在後臺線程中調用UIAlertView,如果字符串長度超過屏幕,模擬器會崩潰。謝謝。 – GMsoF

0

我發現了一個奇怪的行爲,當我顯示JSON對象在字典中解析的結果,然後打印在alertView上(在Xcode 5.1.1上,在iOS 64位模擬器上爲iOS 7.1編譯)。出於同樣的inputData:

[[UIAlertView alloc]initWithTitle:@"something" message:[[[NSString stringWithFormat:@"json:%@",[inputData dictionaryRepresentation]] stringByReplacingOccurrencesOfString:@" "withString:@""]substringToIndex:7035] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil]; 

打印正確,但如果我說「substringToIndex:7036」,僅顯示空白......沒有「stringByReplacingOccurrencesOfString:」法的限制遠遠超出:

[[UIAlertView alloc]initWithTitle:@"something" message:[[NSString stringWithFormat:@"json:%@",[inputData dictionaryRepresentation]] substringToIndex:13768] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil]; 

正確打印,而不是「substringToIndex:13769」不打印...我意識到這不是一個最大長度的問題,但在JSON對象內的特殊字符