UITextView 不显示我的文本
我有一个在详细视图中显示的图像 (jpg) 列表,每个图像都有一个相应的文本文件,其中包含有关该图像的信息。我正在尝试使用 UITextView 来显示文本文件的内容,但我无法让它显示任何内容。我已将文本视图设置为只读,因为我不希望 .txt 文件的内容可编辑。 这就是我所拥有的:
NSString *file = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"txt"];
if (file){
NSString *textFromFile = [NSString stringWithContentsofFile:file];
textView.text = textFromFile;
}
I have a list of images (jpg) that I am displaying in the detailView and each image has a corresponding text file with information about the image. I am trying to use a UITextView to display the contents of the text file, but I have trouble getting it to display anything at all. I have made my text view read-only as I do not want to contents of my .txt files to be editable.
This is what I have:
NSString *file = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"txt"];
if (file){
NSString *textFromFile = [NSString stringWithContentsofFile:file];
textView.text = textFromFile;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能想使用标签来显示非交互式文本的小片段。然后,确保将您决定的 UI 组件与文件所有者链接起来,以便将代码中的变量声明实际连接到 UI 组件。让我知道事情进展如何!
I think that you probably want to use a label to display small snippets of non-interactive text. Afterwards make sure that you link the UI component you decide on with the File Owner in order to actually connect your variable declaration in the code to the UI component. Let me know how this goes!