【问题标题】:UIAlertView maximum text lengthUIAlertView 最大文本长度
【发布时间】:2013-01-24 09:05:03
【问题描述】:

我只想在 UIAlertView 上显示一些文本,但如果文本长度大于允许的大小,则会显示 "Null" 字符串。

我很确定文本不会比屏幕大(大约一半多一点),所以我不想为此复杂地实现 ScrollView

我跟着problem in changing size of uialertview去改变AlertView的大小,但是不起作用,还产生了一些奇怪的视觉效果。

我尝试了这个第三部分组件https://github.com/inamiy/YIPopupTextView,我什至无法通过编译。 (已经将这 4 个文件导入到项目中。)我不知道为什么。

所以,实际上我只是想增加允许在AlertView 上显示的文本大小。有什么想法吗?

【问题讨论】:

  • 你想显示的文字像一个段落?
  • 让您自己的警报视图更容易

标签: iphone ios objective-c


【解决方案1】:

我写了一个小测试程序。这是我添加到单一视图应用程序模板的唯一内容:

- (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 模拟器和运行 iOS 6.0.2 的 iPhone 5 上运行良好。显示所有文本(在可滚动的文本视图中)。

您的问题可能不在于文本的大小。

【讨论】:

  • 是的,那是我的错。我犯的另一个错误是我在后台线程中调用 UIAlertView,如果字符串长度超过屏幕,模拟器会崩溃。谢谢。
【解决方案2】:

当我在字典中显示 JSON 对象的解析结果然后打印在 alertView 上时发现了一个奇怪的行为(在 Xcode 5.1.1 上,在 iphone 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 对象中的特殊字符

【讨论】:

    猜你喜欢
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 2011-07-10
    • 2017-07-05
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多