Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
Hi all,

I am trying to do a simple task:

I have an editable text field, two buttons (titles: make editable/ make un-editable) over a window. Idea is: when user clicks "make editable" button, text field should become editable and when he/she clicks "make un-editable", it should become un-editable.

In action of "make un-editable" I am doing this:

Code:
[myTextField setSelectable:NO];
[myTextField setEditable:NO];

and in action of "make editable" I am doing this:

Code:
[myTextField setSelectable:YES];
[myTextField setEditable:YES];

Problem is:
It works fine when myTextField does not have cursor within it or it has cursor but user does not type anything in it and clicks - "make un-editable", then myTextField becomes un-editable but when it has cursor and user clicks "make un-editable" after typing something within it he/she can still edit myTextField.

For its solution I tried to remove cursor from myTextField as soon as user clicks "make un-editable" button, by adding these lines before selectable and editable statements:

1.
Code:
[someOtherTextField selectText:self];

2.
Code:
[[NSRunLoop currentRunLoop] performSelector:@selector(selectText:) someOtherTextField argument:self order:9999 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];

3.
Code:
[someOtherTextField becomeFirstResponder];

but none is working for me :(

Can anyone suggest some solution for it?

Thanks,

Monaj
 

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
solution found

I used this and solved my problem :)

[[myTextField window] makeFirstResponder: nil]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.