0

我想UITextField在一个线程中获取文本。

IBOutlet UITextField *textSearchBar;

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

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

我知道我可以使用这样的代码来修复它,但我不想用这种方式

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

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

UITextField所以任何人都知道没有'_WebThreadLockFromAnyThread'的任何其他方式来获取文本

4

2 回答 2

2

如果你的目标是 iOS4.0 及以上的设备,那么你可以使用块。更多信息:Grand Central Dispatch

使用块

于 2012-12-04T07:25:29.037 回答
-1

只有一个答案:访问主线程上的 UITextView。

于 2012-12-04T07:01:23.117 回答