In my app I have a UILabel which is the title and a UITextView which is the description and I want the title UILabel to be the first word typed into the UITextView. Does anyone know how to do this?
+2
A:
If I understand well your problem, this code might do the trick:
- (void)textViewDidChange:(UITextView *)textView
{
NSString *text = _textView.text;
NSArray *elements = [text componentsSeparatedByString:@" "];
if ([elements count] > 0)
{
_label.text = [elements objectAtIndex:0];
}
}
Adrian Kosmaczewski
2010-01-03 21:41:45
Thanks! This helped a lot.
timothy5216
2010-01-03 21:51:40
Glad to help :)
Adrian Kosmaczewski
2010-01-03 21:55:52
This will work for English and some other languages that use spaces to separate words, but will fail for many others. To do this the "right" way, use CFStringTokenizer.
sbooth
2010-01-03 22:07:13