4

由于我有静态文本数据,如何在 UIExView 中粘贴长文本。如果我尝试直接粘贴到 textView.text,它会显示错误。如何管理。请指导。提前致谢。

txtView.txt = @"About us

myventr.co is a web-based tool for event creation, event searching and online ticket      selling whilst also serving as a social media network. myventr.co is not just about creating events and buying tickets online but is also a place for you to socialise. You can create your own profile, connect with friends or create your own group for your organisation!

How is this different to other social media websites then? Myevent is about connecting people’s social lives and events all at the same place.  myventr.co will help find all the event details around your location and will also help avoid events clashing by simply searching the Event Calendar before creating an event.";

以上是我正在尝试的方式。

4

8 回答 8

5

不要在下一行使用文本,而是使用 '\n' 作为新行。

于 2013-07-23T11:03:40.843 回答
4

你不能在不同的行中粘贴这样的文本,如果你想要不同的行,你需要自己用\n设置它们。

例如:

@"This is line1\nThis is line 2"
于 2013-07-23T11:03:55.783 回答
4

如果您以编程方式设置它,则必须将其设置在一行中:

txtView.text = @"About us\n\nmyevent.co is a web-based tool for event creation, event searching and online ticket selling whilst also serving as a social media network. myevent.co is not just about creating events and buying tickets online but is also a place for you to socialise. You can create your own profile, connect with friends or create your own group for your organisation!\n\nHow is this different to other social media websites then? Myevent is about connecting people’s social lives and events all at the same place.  myevent.co will help find all the event details around your location and will also help avoid events clashing by simply searching the Event Calendar before creating an event.";
于 2013-07-23T11:09:24.640 回答
1

尝试 :

txtView.txt = @"About us\n myevent.co is a web-based tool for event creation, event searching and online ticket selling whilst also serving as a social media network. myevent.co is not just about creating events and buying tickets online but is also a place for you to socialise. You can create your own profile, connect with friends or create your own group for your organisation! \nHow is this different to other social media websites then? Myevent is about connecting people’s social lives and events all at the same place.  myevent.co will help find all the event details around your location and will also help avoid events clashing by simply searching the Event Calendar before creating an event.";

你得到的错误是你在你的字符串中给出的输入。因此,编译器无法理解语句的结尾。

于 2013-07-23T11:08:13.397 回答
1

添加属性文件'about.plist'

NSDictionary *dic=[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"about" ofType:@"plist"]];
NSLog(@"%@",dic);
于 2013-07-23T11:12:58.057 回答
1

直接在XIB中设置。那可以用换行符自动处理文本。

于 2013-07-23T11:18:43.073 回答
1

如果要在多行上编写文本,可以\在每行末尾添加一个字符。

txtView.txt = @"About us\

myevent.co is a web-based tool for event creation, event searching and online ticket      selling whilst also serving as a social media network. myevent.co is not just about creating events and buying tickets online but is also a place for you to socialise. You can create your own profile, connect with friends or create your own group for your organisation!\

How is this different to other social media websites then? Myevent is about connecting people’s social lives and events all at the same place.  myevent.co will help find all the event details around your location and will also help avoid events clashing by simply searching the Event Calendar before creating an event.";
于 2013-07-23T11:22:30.373 回答
1

我尝试了您的代码,发现您在需要空格的字符串中输入了新的 (\n) 行字符,如其他答案所建议的那样需要空格。我按照您的代码将 Enter 替换为空格,它的工作原理。试试看。建议使用 new line char 换行。

UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(5, 50, 320, 300)];
textView.text = @"About us                                                                                         myventr.co is a web-based tool for event creation, event searching and online ticket      selling whilst also serving as a social media network. myventr.co is not just about creating events and buying tickets online but is also a place for you to socialise. You can create your own profile, connect with friends or create your own group for your organisation!                                                                                                        How is this different to other social media websites then? Myevent is about connecting people’s social lives and events all at the same place.  myventr.co will help find all the event details around your location and will also help avoid events clashing by simply searching the Event Calendar before creating an event."; 
[self.view addSubview:textView];
于 2013-07-23T11:42:17.007 回答