嘿伙计们,我正在尝试从 .rtf 文件加载长文本,我想在 UITextView 中显示此文本。我将所有 .rtf 文件存储在名为“rtf”的文件夹中的“Supporting Files”文件夹中。这是我的代码。
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem)
{
self.textView.text = [self setTextForTextView:[self.detailItem description]];
}
}
-(NSString *)setTextForTextView:(NSString *)description
{
NSString *path = [NSString stringWithFormat:@"rtf/%@.rtf" ,description];
NSLog(@"%@" ,path);
NSString *myText = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
return myText;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Text";
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
但它没有向我显示文字,我不明白为什么......谢谢!