2013-01-24 122 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对象内的特殊字符