1

我似乎找不到可以让我执行以下操作的好的文档:

我有一堆 UTF-8 字符串 JSON'ed 到我的 iPhone 应用程序并显示到 UITableView。当用户点击一个项目时,我想要一个 UIActionSheet 来通知他们他们选择的类别。


替代文字


问题是,虽然中文字符在 UI​​TableView 中显示没有问题,但它们在 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];

提前致谢!

4

1 回答 1

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];

这成功了:


替代文字

于 2010-06-29T09:16:27.150 回答