如何在UITextView中粘贴长文本

时间:2013-07-23 10:58:12

标签: iphone ios

如何在UITexView中粘贴长文本,因为我有静态文本数据。如果我尝试直接粘贴到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.";

以上就是我的尝试方式。

8 个答案:

答案 0 :(得分:5)

请勿在下一行使用文字,而是使用'\ n'作为新行。

答案 1 :(得分:4)

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

例如:

@"This is line1\nThis is line 2"

答案 2 :(得分: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.";

答案 3 :(得分: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.";

您获得的错误是您在字符串中输入的错误。因此,编译器无法理解语句的结束。

答案 4 :(得分:1)

添加属性文件'about.plist'

NSDictionary *dic=[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"about" ofType:@"plist"]];
NSLog(@"%@",dic);

答案 5 :(得分:1)

直接在XIB中设置。这可以用新行自动处理文本。

答案 6 :(得分: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.";

答案 7 :(得分:1)

我尝试你的代码发现你输入字符串你需要空间使用新的(\ n)行字符所需的空间作为其他答案建议。我按照你的代码替换Enter用空格工作。试试吧。建议对新行使用新行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];