1

I have a NSMutableArray * nameCatalog which contains pair of names and urls(name, url).

If I display nameCatalog in viewDidLoad like this:

for (Catalogue *o in nameCatalog){
        NSLog(@"Catalog: %@", o.url);
    }

I get the following links, which is good:

Next I wanna put the NSMutableArray * nameCatalog as content to a table.And I implement the following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSURL *url=[NSURL URLWithString:[[nameCatalog objectAtIndex:indexPath.row] valueForKey:@"url"]];
     NSLog(@"the clicked url:%@", url);

}

So when I click the first row of the table it will be displayed the first url....the second and so on.

When I click first row it gets displayed this

which is correct.

When I click second row it displays this:

which is also correct.

When I click the third row it displays this:

 (null)

which is WRONG!

Where I'm going wrong?

Has anything to do with the fact that the third link contains the french e?

in the word coupé.

IMPORTANT:

Above for simplisity and for make it clear for everyone I assumed that my NSMutableArray contains only 3 urls.

In fact it contains much more, about 20 urls.And everything is going great except the urls that contain french e.When I click those rows of the table NSLog displays null.

And I'm sure that my NSMutableArray contains those links.Please tell me how to fix this?

2 Answers 2

5

Your 3rd string contains 'é' character that may be invalid in url - try to add percent escapes for that character using -stringByAddingPercentEscapesUsingEncoding: function in NSString:

NSString *escapedString = [[[nameCatalog objectAtIndex:indexPath.row] valueForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
Sign up to request clarification or add additional context in comments.

4 Comments

It sounds like a good solution, but too late - The NSURL is probably already created from a string containing the french. OP should try escaping before creating the NSURL from the string.
@Danra, he has strings for url, NSURL are created in didSelectRowAtIndexPath: method, so it's not late it seems
@Vladimir Is better but not perfect.It displays the url but instead of coupé I get coup%C3%A9 .So what next?:D
@george, to display anything to user use strings you already have with proper symbols. When trying to load something using nsurl - use escaped string, that string is not meant to be displayed to user. coup%C3%A9 is the same as coupé, it just uses proper encoding to make it valid url string
0
use this it work fine   
 NSArray *array=[[NSArray alloc] initWithObjects:@"link",@"link",@"link",nil];
        for(int i=0;i<[array count];i++){
            NSString *result = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)[array objectAtIndex:i], NULL, CFSTR("?=&+"), kCFStringEncodingUTF8);
            NSURL *url=[NSURL URLWithString:result];
            NSLog(@"the clicked url:%@", url);
            NSLog(@"%@",[array objectAtIndex:i]);
        } 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.