performselector

iOS performSelectorOnMainThread with multiple arguments

对着背影说爱祢 提交于 2019-12-02 17:53:12
I would like to perform a selector on the main thread from another thread, but the selector has multiple arguments, similar to this: -(void) doSomethingWith:(int) a b:(float)b c:(float)c d:(float)d e:(float)e { //... } How can I get this working with performSelectorOnMainThread: withObject: waitUntilDone: ? EDIT I would like to explain why i need this. I'm working with UIImageViews on the main thread, and I make the calculations for them on another thread. I use a lot of calculations so if i make everything on the main thread, the app lags. I know that UI elements can only be manipulated on

How to Wait in Objective-C and Swift

帅比萌擦擦* 提交于 2019-12-02 16:33:46
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" ? Michał Zygar You can use [self performSelector:@selector(changeText:) withObject:text afterDelay:2.0]; or if you want to display it periodically, check the NSTimer class. I know I am late to this party. But I found people haven't mention thread sleep. If

Memory management in Coregraphics (iOS)

我怕爱的太早我们不能终老 提交于 2019-12-02 11:04:45
问题 I am working on a drawing application, I am using CGlayers for drawing, So I open my canvas for drawing on click of a button, I am using UIBezierPath and then converting it to CGPath in touchesMoved below and then using it to draw -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self

Mac OS, console application. performSelector:withObject:afterDelay: doesn't work?

拟墨画扇 提交于 2019-12-02 08:36:13
I created a simple singleton and run method in it: - (void)run { static int times = 0; NSLog(@"times = %d", times++); [self performSelector:@selector(run) withObject:nil afterDelay:MIN_DELAY]; } But it doesn't work properly. It is executed only once. But if I replace performSelector:withObject:afterDelay: with performSelector: then it will be called a lot of times (but I need a delay between calls). So why method performSelector:withObject:afterDelay: doesn't work? And can I use this method at all? Calls to -performSelector:withObject:afterDelay: require a run loop. Console applications do not

Memory management in Coregraphics (iOS)

 ̄綄美尐妖づ 提交于 2019-12-02 03:23:40
I am working on a drawing application, I am using CGlayers for drawing, So I open my canvas for drawing on click of a button, I am using UIBezierPath and then converting it to CGPath in touchesMoved below and then using it to draw -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self.lineWidth]; pts[3] = midPoint(pts[2], pts[4]);// move the endpoint to the middle of the line joining the

Crash when using performSelector: with a SEL passed from another class

早过忘川 提交于 2019-12-01 14:17:33
Is it possible to send a selector to another class and have it perform on that other class? This seems to crash with the error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[webManager _selector]: unrecognized selector sent to instance . If this is not possible, what would you recommend as an alternative? The methods are placed in the order that they are performed. //in HomeViewController -(void)viewDidLoad { WebManager *webManager = [[WebManager alloc] init]; URLCreator *urlCreator = [[URLCreator alloc] initWithParam:@"default"]; [webManager load:

performSelector:withObject: and its retain behavior

三世轮回 提交于 2019-11-30 09:11:55
This is an already answer question within SO but I cannot find it in the Apple documentation anywhere . Could you point me in the right direction? Within the following topics Do I have to retain an object before passing it to -performSelector:withObject:afterDelay:? the effect on retain count of performSelector:withObject:afterDelay:inModes Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop? the default behaviour seems to be the following: it retains the receiver and the argument(s) . I'm using the following code [[self delegate] performSelector:@selector

performSelector:withObject: and its retain behavior

核能气质少年 提交于 2019-11-29 13:45:03
问题 This is an already answer question within SO but I cannot find it in the Apple documentation anywhere . Could you point me in the right direction? Within the following topics Do I have to retain an object before passing it to -performSelector:withObject:afterDelay:? the effect on retain count of performSelector:withObject:afterDelay:inModes Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop? the default behaviour seems to be the following: it retains the

Return value for performSelector:

走远了吗. 提交于 2019-11-28 17:48:37
What will the return value for performSelector: if I pass a selector that returns a primitive type (on object), such as 'week' on NSDateComponents (which will return an int)? An example of using NSInvocation to return a float: SEL selector = NSSelectorFromString(@"someSelector"); if ([someInstance respondsToSelector:selector]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[someInstance class] instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:someInstance]; [invocation invoke]; float returnValue; [invocation

PerformSelector warning

前提是你 提交于 2019-11-28 07:44:04
I'm receiving a warning PerformSelector may cause a leak because its selector is unknown In the code: - (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err { assert([NSThread isMainThread]); if([delegate respondsToSelector: selector]) { if(arg != NULL) { //this line the warning [delegate performSelector: selector withObject: arg withObject: err]; } else { //this line the warning [delegate performSelector: selector withObject: err]; } } else { NSLog(@"Missed Method"); } } Header: @interface Topscore : UIViewController <NSObject> { // } This is a warning generated by the