I have a UITextField in my iPhone app. I know how to make the text field select all of its text, but how can change the selection? Say I wanted to select the last 5 characte
To select the name of a file without the file extension, use this:
-(void) tableViewCellDidBeginEditing:(UITableViewTextFieldCell*) cell
{
NSInteger fileNameLengthWithoutExt = [self.filename length] - [[self.filename pathExtension] length];
UITextField* textField = cell.textField;
UITextPosition* start = [textField beginningOfDocument];
UITextPosition* end = [textField positionFromPosition:start offset: fileNameLengthWithoutExt - 1]; // the -1 is for the dot separting file name and extension
UITextRange* range = [textField textRangeFromPosition:start toPosition:end];
[textField setSelectedTextRange:range];
}