Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to paste text into a UITextView and each line of text will go to a different UITextField. For example line one in the TextView will move to the first TextField etc...

The code below works perfectly fine but just doesn't reload the data each time i type in something new inside the TextView


What I have tried:

- (void)viewDidLoad {
[super viewDidLoad];

yourArray=[[NSMutableArray alloc]init];

}

-(void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

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];
}
Posted
Comments
Surya_Narayan 2-Jul-16 1:21am    
Its because .. every time u reload your view .. your view did load loaded.. and their you initialize array.. so the old stored data in the array reloaded to nil. The how your text field will show yourArray[0] data. So u need to save the data to show in text field.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900