0

I want to get text of UITextField in a thread.

IBOutlet UITextField *textSearchBar;

{ 
   NSThread* thread ......init:@selector(test)....
   [thread start]
}

-(void)test   
{
    NSString* str = textSearchBar.text;//here to show  '_WebThreadLockFromAnyThread'
}

i know i can use the code like this to fix it, but i do not want to use this way

{ 
   NSThread* thread ......init:@selector(test)..withObject:textSearchBar.text];....
   [thread start]
}

-(void)test:(NSString*)textStr
{
    NSString* str = textStr;
}

so anyone knows any other way to get text from UITextField without '_WebThreadLockFromAnyThread'

iDev
  • 23,310
  • 7
  • 60
  • 85
zt9788
  • 948
  • 4
  • 16
  • 31

2 Answers2

2

If you are targeting the devices with iOS4.0 and above, then you could use blocks. More info on that : Grand Central Dispatch.

Working with blocks

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
-1

There is only one answer: Access the UITextView on the main thread.

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • yes,i kown it .beacause i need do other things in thread,so i need got text frist,so could you post some code to fix this question? – zt9788 Dec 04 '12 at 07:08
  • You already did, that is the correct way to do it. I don't know any other way unless you want to use `performSelectorOnMainThread` to get the text – borrrden Dec 04 '12 at 07:14
  • - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait; the function can not get return value.and if i definition a variable to get it,the thread may not got. – zt9788 Dec 04 '12 at 07:18
  • Then you need to do it the way you described whether you "want to" or not. – borrrden Dec 04 '12 at 07:26