performselector

Best way to performselectoronmainthread in objective c?

馋奶兔 提交于 2019-12-04 11:54:05
问题 I'm writing a client-server app to iPhone. And I have a question about threading. When I access my online database from the device, I need to do this on a separate thread to not freeze the UI/main thread. But when responding to the data I've fetched from the database I call this method on the main thread: performSelectorOnMainThread. The thing is that this only lets me send one argument/object to the method (WithObject), sometimes I have more arguments I want to pass. and another thing about

scheduledTimerWithTimeInterval vs performselector with delay with iOS 5.0

筅森魡賤 提交于 2019-12-04 03:14:29
i am doing function call with scheduledTimerWithTimeInterval. i am just checking that xml parsing is completed or not for particular web services and invalidating timer in didEndElement method after getting successful response. timerForStopWebService = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(stopWS) userInfo:nil repeats:NO]; now i am facing problem with iOS 5.0 and its working fine in other iOS versions. in iOS 5.0, a function stopWS call anytime even if i am invalidating it. let me know if you have solution for that. and now i am implementing

Crash in objc_retain in method performed with performSelector

自闭症网瘾萝莉.ら 提交于 2019-12-04 02:58:59
I have this strange crash relating to ARC auto-inserting objc_retains in my code. I have the following two classes: @interface MenuItem : NSObject @property (weak, nonatomic) id target; @property (unsafe_unretained, nonatomic) SEL action; @property (strong, nonatomic) id object; - (instancetype)initWIthTarget:(id)target action:(SEL)action withObject:(id)object; - (void)performAction; @end @implementation MenuItem - (void)performAction { if (self.target && self.action) { if (self.object) { [self.target performSelector:self.action withObject:self.object]; } else { [self.target performSelector

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

≡放荡痞女 提交于 2019-12-04 02:31:30
问题 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]

How to call a method a.s.a.p. but at earliest in the next run loop iteration?

一笑奈何 提交于 2019-12-03 11:30:57
问题 I need a save way to say: "iOS, I want this method to be executed a.s.a.p., but NOT in THIS run loop iteration. At the earliest in the next, but please not in this one. Thank you." Right now I am always doing it like this: [self performSelector:@selector(doSomethingInNextRunLoop) withObject:nil afterDelay:0]; [self doSomeOtherThings]; With the assumption that -doSomeOtherThings will always be performed BEFORE -doSomethingInNextRunLoop . The documentation says: Specifying a delay of 0 does not

Best way to performselectoronmainthread in objective c?

ⅰ亾dé卋堺 提交于 2019-12-03 07:20:00
I'm writing a client-server app to iPhone. And I have a question about threading. When I access my online database from the device, I need to do this on a separate thread to not freeze the UI/main thread. But when responding to the data I've fetched from the database I call this method on the main thread: performSelectorOnMainThread. The thing is that this only lets me send one argument/object to the method (WithObject), sometimes I have more arguments I want to pass. and another thing about it is that I HAVE TO pass this one object. I can't pass nil, if I do the app crashes. This is my code

iOS performSelectorOnMainThread with multiple arguments

吃可爱长大的小学妹 提交于 2019-12-03 04:43:25
问题 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

comparison GCD vs. performSelectorInBackground: dispatch_async not in background

独自空忆成欢 提交于 2019-12-03 04:39:04
问题 Grand Central Dispatch is great and reduces the amount of code but why I cannot run something on a background thread? I have made a sample application to show what I mean (none of the commented work): - (IBAction)performSel { [self performSelectorInBackground:@selector(doStuff) withObject:nil]; [NSThread sleepForTimeInterval:3]; [[self.view.subviews lastObject] removeFromSuperview]; } - (IBAction)gcd { dispatch_async(dispatch_queue_create("myGCDqueue", NULL), ^(void) { //dispatch_sync

How to call a method a.s.a.p. but at earliest in the next run loop iteration?

人走茶凉 提交于 2019-12-03 01:54:39
I need a save way to say: "iOS, I want this method to be executed a.s.a.p., but NOT in THIS run loop iteration. At the earliest in the next, but please not in this one. Thank you." Right now I am always doing it like this: [self performSelector:@selector(doSomethingInNextRunLoop) withObject:nil afterDelay:0]; [self doSomeOtherThings]; With the assumption that -doSomeOtherThings will always be performed BEFORE -doSomethingInNextRunLoop . The documentation says: Specifying a delay of 0 does not necessarily cause the selector to be performed immediately. The selector is still queued on the thread

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

时光毁灭记忆、已成空白 提交于 2019-12-02 17:59:18
问题 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