performselector

Threads and autoreleasepool questions

感情迁移 提交于 2019-12-24 16:18:15
问题 As I understand there are several ways to send tasks to be performed in threads. The most common ones that I use are: 1) performSelector:withObject:afterDelay: 2) performSelectorOnMainThread:withObject:waitUntilDone: 3) performSelectorInBackground:withObject: 4) [NSThread detachNewThreadSelector:toTarget:withObject:] My first question is, what is the difference between 1) and 2), besides the obvious parameter differences? Are they actually both working in the Main thread (whose autorelease

why warning with my performSelector

前提是你 提交于 2019-12-24 07:37:17
问题 Below is a simple PerformSelector that sends a message to obj to perform the looping method. All works well but I get the following yellow warning. PerformSelector may cause a leak because its selector is unknown. #import "MyClass.h" #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { MyClass *obj = [[MyClass alloc]init]; SEL mySel = @selector(looping); [obj performSelector:mySel]; } return 0; } This warning does not make sense because the

How to multithred correctly? UIAlertView is not displayed, only gray screen

筅森魡賤 提交于 2019-12-24 02:59:10
问题 i have implemented textToSpeech in my project and want to display an alertview while text is spoken. here i am calling the methods for textToSpeech: //-----before TTS starts i try to display alertView with Cancelbutton //[self performSelectorOnMainThread:@selector(alertWhileTTS) withObject:nil waitUntilDone:YES]; //gray view and no alertview //[self performSelector:@selector(alertWhileTTS)]; //gray view and no alertview //[self alertWhileTTS]; //gray view and no alertview //this part here is

performSelector in NSOperation subclass

[亡魂溺海] 提交于 2019-12-24 00:52:35
问题 I couldn't find an answer anywhere else on the net so any help would be appreciated. I am tying to create a system whereby I can retrieve the results of an NSOperation task, which I understand cannot be done by concrete subclasses such as NSInvocation. I have an NSOperation subclass ( TheEngine ) which is abstract by convention and must be extended to implement the function -main , to include the body of code to execute. TheEngine contains the following initialisation function whose job is

pass block as parameter in my case

依然范特西╮ 提交于 2019-12-22 01:48:26
问题 I have a function which takes a block as parameter: typedef void (^ MyBlock)(int); -(void)doTask:(MyBlock)theBlock{ ... } I need to run above function on another thread, I want to use - performSelector:onThread:withObject:waitUntilDone: , my current code: NSThread *workerThread = [[NSThread alloc] init]; [workerThread start]; [self performSelector:@selector(doTask:) onThread:workerThread withObject:??? waitUntilDone:NO]; BUT, How can I pass MyBlock parameter with this approach? (Please don't

How to Wait in Objective-C and Swift

橙三吉。 提交于 2019-12-20 08:39:55
问题 I want to change my UILabel 's text after 2 seconds. I tried setting my UILabel 's text to "A text" , and use sleep(2) and finally changing the text to "Another text" . But sleep(2) only freezes the app and "Another text" is set without displaying "A text" for 2 seconds. How may I display "A text" for 2 seconds and then show "Another text" ? 回答1: You can use [self performSelector:@selector(changeText:) withObject:text afterDelay:2.0]; or if you want to display it periodically, check the

How to use performselector to involve the function with argument after particular time period

牧云@^-^@ 提交于 2019-12-20 06:36:53
问题 I am new to this iPhone app programming. I have a function with one argument type as structure pointer. This is shown below (void)responce:(structurePtr *)someData { ...... ...... } I want to call this function using performselector method after 5 seconds of time interval. Please tell me how to call above responce function using performselector Thanks in advance. 回答1: Use: - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay [yourObject

UILabel won't update even on dispatch_async

て烟熏妆下的殇ゞ 提交于 2019-12-13 08:36:09
问题 Any reason why my label won't update? - (void)setLabel:(NSNotification*)notification { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"setLabel"); [self.label setText:@"My Label"]; }); } I've also tried using performSelectorOnMainThread to no avail. Note that setLabel is appears on the log. Additional info: I also have two other functions which does the same thing but only with a different text. The two other functions doesn't have dispatch_async but they both work. Also, the

CABasicAnimation is not working when the method is called from the viewDidLoad

你说的曾经没有我的故事 提交于 2019-12-12 05:13:17
问题 I have an imageView added to a view that's presented as a modalViewController, with style horizontal flip. I have added the following code for animating the imageView. - (void)animateTheImageview:(UIImageView*) imageViewToAnimate{ CABasicAnimation *fadeAnimation; fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeAnimation.duration = 1.5; fadeAnimation.repeatCount = INFINITY; fadeAnimation.autoreverses = NO; fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0];

performSelector:onThread breaks runloop?

匆匆过客 提交于 2019-12-11 17:57:25
问题 I'm not sure how to use the API performSelector:onThread and I need some suggestions here. As far as I known, I need a runloop to make the call of performSelector:onThread , so I made one. But then I find a problem : once I called performSelector:onThread , the runloop stops. Here 's my test code, runloop is in function kickOffThread . - (void)setCurrentThread { self.thread = [NSThread currentThread]; } - (void)kickOffThread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [self