Warning: UIKit should not be called from a secondary thread

前端 未结 5 1513
悲哀的现实
悲哀的现实 2020-12-10 00:44

In my iPhone app I need to connect to a web server as this can take some time I\'m using threads like this:

[NSThread detachNewThreadSelector:@selector(sendS         


        
5条回答
  •  执念已碎
    2020-12-10 01:09

    It depends a little bit on what you want to do with the textField. If reading the value is the only thing, you can do:

    [NSThread detachNewThreadSelector:@selector(sendStuff) toTarget:self withObject:self.textField.text];
    
    - (void)sendStuff:(NSString*)myString {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        //Do someting with myString
        [pool release];
    }
    

    If you want to change a value on the textField you could:

    [self.textField performSelectorOnMainThread:@selector(setText:) withObject:@"new Text"];
    

提交回复
热议问题