1

我有一个数据库,其中包含一个名称列表和每个名称的注释,我在 tableview 中列出这些名称没有问题,但是当我单击一个名称以获取它的注释时,我没有得到任何结果,只有阿拉伯语名称,但是当我选择一个英文名称时,我得到了结果。所以我认为问题出在 xcode 上,如果它有阿拉伯字符,则无法发送链接。

当我将链接放入 safari 时,我得到英文和阿拉伯名称的结果,所以我确定我的 php 代码没问题。

我在 xcode 中使用的代码是

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *tempTitle = [NSString stringWithFormat:@"%@", [array objectAtIndex:indexPath.row]];

NSString *strURL = [NSString stringWithFormat:@"http://localhost/getComment.php?name=%@",tempTitle];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

NSLog(@"url : %@", strURL);
NSLog(@"result : %@", strResult);
NSLog(@"title : %@", tempTitle);
}

知道如何解决吗?

4

1 回答 1

0

通过替换此代码解决了问题

NSData *dataURL =[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
于 2012-10-02T15:31:18.357 回答