thanks for the great tutorial. but i have one problem. i’m actually using a UITextView for the tweet input instead of a UITextField. the problem is that the “editing changed” event is not part of the UITextView’s options. Any way to make this work? Or is there a ways to make text wrap in a UITextField? Thanks
Just a note that this is the same method you can use to make a string longer. The withString argument is just a placeholder that’s used when extending rather than shortening the string.
Your step 3 describes dragging from the “Editing Changed” action to “File’s Owner”, but the graphic you display there is what you’d get if you had selected File’s Owner and opened the Connections tab, and then dragged from the Received Action textFieldDidUpdate to the textField on the View and scrolled to “Editing Changed”.
Right now, I’m not getting it to work either way in that the NSLog operation takes off and never stops creating blank entries, so I figure I’m missing a line of code involving “naughtyWord”. (I’m new to C).
16 Comments
thanks for the great tutorial. but i have one problem. i’m actually using a UITextView for the tweet input instead of a UITextField. the problem is that the “editing changed” event is not part of the UITextView’s options. Any way to make this work? Or is there a ways to make text wrap in a UITextField? Thanks
For a UITextView, set it’s delegate to your class and implement this method:
-(void)textViewDidChange:(UITextView *)textView {
int len = textView.text.length;
}
*This is a delegate method of UITextView
Hope that helps.
Hmm thats not helping very much srry.
@Bob
This is what i’ve done to get it working with a textView:
-(void)textViewDidChange:(UITextView *)textView {
int maxChars = 140;
int charsLeft = maxChars – [tweetMessage.text length];
if(charsLeft == 0) {
liveOutputTextView.textColor = [UIColor redColor];
}
liveOutputTextView.text = [NSString stringWithFormat:@"%d",charsLeft];
}
I’ve also taken out the UIAleart and instead made it simply turn the text red when it’s at 0 or below.
@brandontreb thanks again for the help!
I was playing around and got a version where it will prevent the user from going over the given number of characters.
In at the top of the view controller header file:
#define totalChars 140
For the field did update method in the view controller .m file:
-(IBAction)fieldDidUpdate:(id)sender {
UITextField *textField = (UITextField *)sender;
int remainingChars = totalChars – [textField.text length];
liveOutputTextView.text = [[NSString alloc] initWithFormat:
@”You have %d characters remaining.”, remainingChars];
if ([textField.text length] > totalChars)
textField.text =
[textField.text stringByPaddingToLength:totalChars withString:@"." startingAtIndex:0];
}
Just a note that this is the same method you can use to make a string longer. The withString argument is just a placeholder that’s used when extending rather than shortening the string.
This tutorial, and the comments about UITextView were very helpful. Thanks for sharing.
very nice tutorial..
it’s helping me so much 
Do you have a video of this tutorial?
I just cant get it work with the UITextField :S want to use it with the tut of the twitter updater
Sean Luan or Darko would like that base 2 to base 10 convertor
Thank you to all of the assist
mucho helpful and very much appreciated. thanks man! now if i could only figure out how to get it to let me change the color of specific words…
Sean,
You’ll have to use a UIWebView for that. Then you can specify HTML instead of plain text and build complex styles however you like.
Tyler
Your step 3 describes dragging from the “Editing Changed” action to “File’s Owner”, but the graphic you display there is what you’d get if you had selected File’s Owner and opened the Connections tab, and then dragged from the Received Action textFieldDidUpdate to the textField on the View and scrolled to “Editing Changed”.
Right now, I’m not getting it to work either way in that the NSLog operation takes off and never stops creating blank entries, so I figure I’m missing a line of code involving “naughtyWord”. (I’m new to C).
Thanks for great tutorial….this tutorial really help in my work…
Amit
for(NSString * naughtyWord in filteredWords.allKeys)should be written as
for(NSString * naughtyWord in filteredWords)One Trackback
[...] Original post on iCodeBlog [...]