2013-09-30 6 views
1

Existe-t-il un moyen d'avoir une sorte de texte enrichi dans un fichier et de charger le fichier dans un NSAttributedString? J'ai regardé dans le chargement d'un fichier .rtf dans une chaîne NSAttributed:Charger NSAttributedString à partir du fichier

NSString *filePathFooter = [[NSBundle mainBundle] pathForResource:kFooterFileName ofType:@"rtf"]; 

NSError *error = nil; 
NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:[NSURL URLWithString:filePathFooter] 
                   options:nil 
                 documentAttributes:NULL 
                    error:&error]; 

Mais cela me laisse avec:

Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn’t be completed. (Cocoa error 258.)" 

Est-il possible de le faire?

Répondre

0

NSCocoaErrorDomain le code d'erreur 258 est NSFileReadInvalidFileNameError, donc il semble qu'il ne trouve pas le fichier que vous transmettez.

4

Utilisez plutôt URLForResource et passer l'URL résultante comme ceci:

NSURL *url = [[NSBundle mainBundle] URLForResource:kFooterFileName withExtension:@"rtf"]; 

NSError *error = nil; 
NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:url 
                   options:nil 
                 documentAttributes:NULL 
                    error:&error]; 
Questions connexes