2013-07-23 81 views
4

我怎么能贴上长文在UITexView因为我有静态的文本数据。如果我尝试直接粘贴到textView.text,它会显示错误。这可以如何管理。请指导。 在此先感谢。如何粘贴长文本中的UITextView

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."; 

以上是我努力的方式。

+0

@HinataHyuga在程序中意外的@和缺少终止字符。 –

+0

你得到哪种类型的错误:) – Rushabh

+0

你在那里输入新行吗? –

回答

5

不要使用下一行的文本,而不是用“\ n”的新行。

4

无法粘贴像在不同行的文本,如果你想拥有你需要自行设置与\ n个不同的线路。

例如:

@"This is line1\nThis is line 2" 
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

如果设置程序,你必须将其设置在同一行:

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."; 
1

直接在XIB添加属性文件 'about.plist'

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

Jain你能告诉我如何添加到plist,我正在尝试通过将文本文件添加到项目中的方式。如何添加plist? –

+0

1.右键单击左窗格中的文件并选择“新文件...”选项。 2.从OS X选项卡选择资源。 3.属性列表的选项可用。 4.选择一个合适的名称。 这会被添加到您的项目中。 –

+1

这也是一个选项,我试过也可以。 –

1

设置。这可以用新行自动处理文本。

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."; 
1

我试试你的代码中发现你给在你需要的空间使用新的(\ n)的行,其中所需的空间,其他的答案suggested.I按照你的代码字符字符串输入空格替换其working.Try它进入。建议对新行使用新的行字符。

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];