[英]How to change text in UITextView and UITextField
I need to edit my UITextView
and when I make these changes I need them to reflect that in my UITextFields
.我需要编辑我的UITextView
,当我进行这些更改时,我需要它们在我的UITextFields
反映出来。 Currently i can use the code below to move whatever text i write into the first UITextField
is there a simple way to move each line to a separate UITextField
?目前我可以使用下面的代码将我写的任何文本移动到第一个UITextField
是否有一种简单的方法可以将每一行移动到单独的UITextField
?
Like the image, except the 1, 2 and 3 going to a different UITextField
.像图像一样,除了 1、2 和 3 转到不同的UITextField
。
-(IBAction)print:(id)sender {
NSString *texto = [[NSString alloc] initWithFormat:@"%@ %@",[myTextField text],[myTextView text]];
[myTextField setText:texto];
[myTextView setText:@""];
[myTextView resignFirstResponder];
}
Really, I need to figure this out.真的,我需要弄清楚这一点。 Any help will be appreciated.任何帮助将不胜感激。
Have your view controller conform to the UITextViewDelegate
protocol.让您的视图控制器符合UITextViewDelegate
协议。
Next, set the delegate
property of your text view to your view controller.接下来,将文本视图的delegate
属性设置为视图控制器。
Then, implement - (void)textViewDidChange:(UITextView *)textView
, along these lines:然后,按照以下方式实现- (void)textViewDidChange:(UITextView *)textView
:
- (void)textViewDidChange:(UITextView *)textView
{
// Set the text for your text fields.
//
// (I'm assuming your code for determining the text to put in the
// text fields works as you intend, so I'm just copying it here.)
NSLayoutManager *layoutManager = [textView layoutManager];
unsigned numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];
NSRange lineRange;
for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++)
{
(void) [layoutManager lineFragmentRectForGlyphAtIndex:index
effectiveRange:&lineRange];
index = NSMaxRange(lineRange);
NSString *lineText = [textView.text substringWithRange:lineRange];
[yourArray addObject:lineText];
}
textField1.text=yourArray[0];
textField2.text=yourArray[1];
textField3.text=yourArray[2];
textField4.text=yourArray[3];
textField5.text=yourArray[4];
textField6.text=yourArray[5];
textField7.text=yourArray[6];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.