我似乎找不到可以让我执行以下操作的好文档:
我有一堆UTF-8字符串JSON'ed到我的iPhone应用程序并显示到UITableView。当用户点击某个项目时,我想要一个UIActionSheet来通知他们他们选择的类别。
alt text http://img684.imageshack.us/img684/4395/so20100629.png
问题在于,虽然汉字在UITableView中显示没有问题,但它们在UIActionSheet中显示为UTF-8字符。有没有办法将它从UTF-8转换成繁体中文字符?
我试图这样做,但它不起作用:
const char *subCatName = [[thirdParamStringArr objectAtIndex:1] UTF8String];
NSString *subCatSelectedConverted = [[NSString alloc] initWithUTF8String:subCatName];
NSString *actionSheetTitle = [@"You have selected " stringByAppendingString:subCatSelectedConverted];
NSString *actionSheetTitleFinal = [actionSheetTitle stringByAppendingString:@", proceed to upload to selected subcategory?"];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitleFinal delegate:self cancelButtonTitle:@"Proceed to Upload" destructiveButtonTitle:@"Cancel" otherButtonTitles:nil];
提前致谢!
答案 0 :(得分:2)
好的,经过进一步调查后,这就成了伎俩:
NSString *subCatSelectedName = [[thirdParamStringArr objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *actionSheetTitle = [@"You have selected '" stringByAppendingString:subCatSelectedName];
NSString *actionSheetTitleFinal = [actionSheetTitle stringByAppendingString:@"', proceed to upload to selected subcategory?"];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitleFinal delegate:self cancelButtonTitle:@"Proceed to Upload" destructiveButtonTitle:@"Cancel" otherButtonTitles:nil];
这就是诀窍:
alt text http://img709.imageshack.us/img709/8703/so201006292.png