views:

85

answers:

1

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
Thanks! This helped a lot.
timothy5216
Glad to help :)
Adrian Kosmaczewski
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