关于UITextView使用及无法显示文本的解决方案。

首先说一下不显示的解决:

1.考虑编码格式

国际通用的是UTF-8,汉字的是GBK。另外,可以看下文档中NSStringEncoding的所有取值,其实不止这些,可以用代码输出所有编码格式,如下:

    const NSStringEncoding *encodings = [NSString availableStringEncodings];

    NSMutableString *str = [[NSMutableString alloc] init];

    NSStringEncoding encoding;

    while ((encoding = *encodings++) != 0){

      [str appendFormat: @"%@ === %in", [NSString localizedNameOfStringEncoding:encoding], encoding];

    }

    NSLog(@"%@",str);

打印出所有支持的编码列表如下:

Western (Mac OS Roman) === 30

Japanese (Mac OS) === -2147483647

Traditional Chinese (Mac OS) === -2147483646

Korean (Mac OS) === -2147483645

Arabic (Mac OS) === -2147483644

Hebrew (Mac OS) === -2147483643

Greek (Mac OS) === -2147483642

Cyrillic (Mac OS) === -2147483641

Devanagari (Mac OS) === -2147483639

Gurmukhi (Mac OS) === -2147483638

Gujarati (Mac OS) === -2147483637

Thai (Mac OS) === -2147483627

Simplified Chinese (Mac OS) === -2147483623

Tibetan (Mac OS) === -2147483622

Central European (Mac OS) === -2147483619

Symbol (Mac OS) === 6

Dingbats (Mac OS) === -2147483614

Turkish (Mac OS) === -2147483613

Croatian (Mac OS) === -2147483612

Icelandic (Mac OS) === -2147483611

Romanian (Mac OS) === -2147483610

Celtic (Mac OS) === -2147483609

Gaelic (Mac OS) === -2147483608

Keyboard Symbols (Mac OS) === -2147483607

Farsi (Mac OS) === -2147483508

Cyrillic (Mac OS Ukrainian) === -2147483496

Inuit (Mac OS) === -2147483412

Unicode (UTF-32LE) === -1677721344

Unicode (UTF-8) === 4

Unicode (UTF-16) === 10

Unicode (UTF-16BE) === -1879047936

Unicode (UTF-16LE) === -1811939072

Unicode (UTF-32) === -1946156800

Unicode (UTF-32BE) === -1744830208

Western (ISO Latin 1) === 5

Central European (ISO Latin 2) === 9

Western (ISO Latin 3) === -2147483133

Central European (ISO Latin 4) === -2147483132

Cyrillic (ISO 8859-5) === -2147483131

Arabic (ISO 8859-6) === -2147483130

Greek (ISO 8859-7) === -2147483129

Hebrew (ISO 8859-8) === -2147483128

Turkish (ISO Latin 5) === -2147483127

Nordic (ISO Latin 6) === -2147483126

Thai (ISO 8859-11) === -2147483125

Baltic Rim (ISO Latin 7) === -2147483123

Celtic (ISO Latin  ===

-2147483122

Western (ISO Latin 9) === -2147483121

Romanian (ISO Latin 10) === -2147483120

Latin-US (DOS) === -2147482624

Greek (DOS) === -2147482619

Baltic Rim (DOS) === -2147482618

Western (DOS Latin 1) === -2147482608

Greek (DOS Greek 1) === -2147482607

Central European (DOS Latin 2) === -2147482606

Cyrillic (DOS) === -2147482605

Turkish (DOS) === -2147482604

Portuguese (DOS) === -2147482603

Icelandic (DOS) === -2147482602

Hebrew (DOS) === -2147482601

Canadian French (DOS) === -2147482600

Arabic (DOS) === -2147482599

Nordic (DOS) === -2147482598

Cyrillic (DOS) === -2147482597

Greek (DOS Greek 2) === -2147482596

Thai (Windows, DOS) === -2147482595

Japanese (Windows, DOS) === 8

Simplified Chinese (Windows, DOS) === -2147482591

Korean (Windows, DOS) === -2147482590

Traditional Chinese (Windows, DOS) === -2147482589

Western (Windows Latin 1) === 12

Central European (Windows Latin 2) === 15

Cyrillic (Windows) === 11

Greek (Windows) === 13

Turkish (Windows Latin 5) === 14

Hebrew (Windows) === -2147482363

Arabic (Windows) === -2147482362

Baltic Rim (Windows) === -2147482361

Vietnamese (Windows) === -2147482360

Western (ASCII) === 1

Japanese (Shift JIS X0213) === -2147482072

Chinese (GBK) === -2147482063

Chinese (GB 18030) === -2147482062

Japanese (ISO 2022-JP) === 21

Korean (ISO 2022-KR) === -2147481536

Japanese (EUC) === 3

Simplified Chinese (EUC) === -2147481296

Traditional Chinese (EUC) === -2147481295

Korean (EUC) === -2147481280

Japanese (Shift JIS) === -2147481087

Cyrillic (KOI8-R) === -2147481086

Traditional Chinese (Big 5) === -2147481085

Western (Mac Mail) === -2147481084

Simplified Chinese (HZ GB 2312) === -2147481083

Traditional Chinese (Big 5 HKSCS) === -2147481082

Ukrainian (KOI8-U) === -2147481080

Traditional Chinese (Big 5-E) === -2147481079

Western (NextStep) === 2

Non-lossy ASCII === 7

Western (EBCDIC Latin 1) === -2147480574

from:http://hi.baidu.com/may2150209/blog/item/198976ace7e583054b36d6f1.html

2.创建tv后做一个赋值tv = nil;

  在苹果的developer library上UILable的text属性默认是nil,而UITextView却没提(有待考证)。

 

UITextView的使用:

  首先说一下TextView键盘的退出,只需要一句:[textView resignFirstResponder];,至于退出的方式,网上看到三种(前两种需要使用UITextViewDelegate):1.在导航条上加一个按钮。2.用键盘(手机上电脑上均适用)的回车键。3.在弹出的键盘上加一个UIView来放置退出键盘按钮。

具体实现可参考:http://wuchaorang.2008.blog.163.com/blog/static/48891852201232014813990/

  还有自定义TextView内选取文字后弹出菜单的方法。

posted @ 2012-09-06 13:06  pointer2011  阅读(2832)  评论(0编辑  收藏  举报