Hi, I created an app that counts the lines in a text view. I got it to work like this:
- (void)awakeFromNib
{
string = [textView string];
unsigned numberOfLines;
unsigned index;
unsigned stringLength = [string length];
for (index = 0, numberOfLines = 0; index < stringLength; numberOfLines++)
{
index = NSMaxRange([string lineRangeForRange:NSMakeRange(index, 0)]);
[textField setIntValue:numberOfLines + 1];
}
}
I put '+ 1' because, I don't know why, it starts from zero. It works perfectly except It just counts them once. If you modify the text view, the text field doesn't change. How can I make it to coninuously check for changes in the text view?
- (void)awakeFromNib
{
string = [textView string];
unsigned numberOfLines;
unsigned index;
unsigned stringLength = [string length];
for (index = 0, numberOfLines = 0; index < stringLength; numberOfLines++)
{
index = NSMaxRange([string lineRangeForRange:NSMakeRange(index, 0)]);
[textField setIntValue:numberOfLines + 1];
}
}
I put '+ 1' because, I don't know why, it starts from zero. It works perfectly except It just counts them once. If you modify the text view, the text field doesn't change. How can I make it to coninuously check for changes in the text view?