ios - NSMutableString appendFormat 遇到的问题 附上内容 请帮忙看看,问题很怪异!!!
PHPz
PHPz 2017-04-18 09:42:59
0
2
615

NSMutableString* str_attachMent = [NSMutableString stringWithFormat:@"附件(%ld):",attachedCount];

for ( int i = 0 ; i < attachedCount ; i++) { FileInfo *fileInfo = (FileInfo*)mailInfo.attachedArr[i]; if (i < mailInfo.attachedCount - 1) { [str_attachMent appendFormat:@"%@;",fileInfo.fileName]; }else { [str_attachMent appendString:fileInfo.fileName]; } }

最后str_attachMent得到拼装好的字符串是如下内容:
附件(9): 404.HTML;BLOG.HTML;BLOG_SINGLE.HTML;CONTACT.HTML;INDEX.HTML;LOGIN.HTML;MEN.HTML;REGISTER.HTML;SINGLE.HTML
可以把内容复制到记事本上面试验下,为什么强行被换行了,而且我是没办法把404这行移到附件(9):后面
[str_attachMent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 移除空格和换行也没有作用.

我估计是拼装内容的问题,但是这个问题没有办法解决么.

PHPz
PHPz

学习是最好的投资!

reply all (2)
小葫芦

It is not a forced career change. During typesetting, the system will
"404.HTML;BLOG.HTML;BLOG_SINGLE.HTML;CONTACT.HTML;INDEX.HTML;LOGIN.HTML;MEN.HTML;REGISTER.HTML;SINGLE.HTML" Zu is a word. When it is displayed, the current line where "Attachment (9):" is located cannot display it completely, so it automatically jumps to the next line for display, unless the text box you display is wide enough. Just like if you directly print this sentence like this when posting a question, it will also be displayed in a new line,
Attachment (9): 404.HTML;BLOG.HTML;BLOG_SINGLE.HTML;CONTACT.HTML;INDEX.HTML;LOGIN. HTML;MEN.HTML;REGISTER.HTML;SINGLE.HTML
But if you add a space after each semicolon, the effect is like this:
Attachment (9): 404.HTML; BLOG.HTML; BLOG_SINGLE.HTML; CONTACT.HTML; INDEX.HTML; LOGIN.HTML; MEN.HTML; REGISTER.HTML; SINGLE.HTML
Because you added spaces to distinguish each semicolon as a whole, so it will not appear during typesetting This question of yours.

    大家讲道理

    For UITextView, various UI controls that process text will change the layout of the text, which can be solved by using NSMutableAttributedString.
    NSString* str = [NSString stringWithFormat:@"Attachment (%ld):",str1];

    NSMutableParagraphStyle* linebreak = [[NSMutableParagraphStyle alloc]init]; linebreak.lineBreakMode = NSLineBreakByCharWrapping; NSMutableAttributedString *str_attachMent = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSParagraphStyleAttributeName:linebreak}]; textView.attributedText = str_attachMent;
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!