Is there a way to do multiple actions respectively using the : performSelector:withObject:afterDelay code ? Sample code will be appreciated , Thanks in advance.
Asked
Active
Viewed 129 times
0
-
Given the offline chat, I'm assuming you want to do something like http://stackoverflow.com/questions/12739506/how-to-send-mms-from-iphone-app/12739608#12739608. But rather than doing a `afterDelay` or `dispatch_after`, if you do anything, you might want use the `completion` block of the `presentViewController`. But I'm not clear how you initiate the paste in that other controller. The general consensus is that it's not possible without some custom MMS gateway or something horribly kludgy like this. Yikes. – Rob Oct 20 '12 at 05:26
-
I saw this sample code before but I don't know how I use it for my needs, as you know my needs do you have any idea how to do it? Because I need to copy the photo first before I can paste. – 4slices Oct 20 '12 at 13:15
-
That code related to the `UIPasteboard` does the copy of the photo and then initiates the SMS, so I'm not sure what you're asking. But, to my prior point, this code does _not_ paste, and I don't think you can, which serious undermines the usefulness of that code, IMHO. It requires the user to manually paste themselves. All he's doing is filling the `UIPasteboard`. If you have further questions, I'd probably suggest you post a comment on that post, as the author was quick to respond when I asked a question. – Rob Oct 20 '12 at 13:30
2 Answers
1
Or use blocks. If you start to type dispatch_after
, you'll see code completion that will pop up the following snippet of code, and then you can put however many actions you want in that block. In this example, I'm showing it being used inside an IBAction
:
- (IBAction)pushedSomeButton:(id)sender
{
// anything you want to do immediate, do here
[self doingSomethingRightNow];
// anything you want to defer for some time, do inside the dispatch_after block
// in this example, calling callAnotherMethod and whyNotCallAnotherMethod
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self callAnotherMethod];
[self whyNotCallAnotherMethod];
});
}

Rob
- 415,655
- 72
- 787
- 1,044
-
-
Is this the code I need to put inside the main IBAction connected to my button? If so the rest of actions will I put inside the two brackets after ^(void) or where? Can you please explain with example and more details , I'm still new in coding. Thank you. – 4slices Oct 20 '12 at 04:34
-
Yep, between the two brackets after `^(void)`. Using runmad's example, I imagined the stuff you were going to run involved running two methods, `callAnotherMethod` and `whyNotCallAnotherMethod`. I also contemplated that maybe there was some portion you wanted to do immediately, in `doingSomethingRightNow`. If this still doesn't make sense and you want a more realistic example, you might to give us some sort of clues as to what you're really trying to do. – Rob Oct 20 '12 at 04:41
-
Actually what I want to do is : 1-copy a picture which I already have in a view. 2-Present another view. 3-Paste the picture in the presented view. This is my plan. – 4slices Oct 20 '12 at 04:53
-
Shall we continue this in chat? http://chat.stackoverflow.com/rooms/18326/conversation-bw-4slices-and-rob – Rob Oct 20 '12 at 05:00
-
Not sure how you'd accomplish #3. Strikes me that in the absence of any proper MMS internal solution that you'd either have to use some commercial MMS solution, or just upload the image to some cloud based service and then include URL in SMS. – Rob Oct 20 '12 at 06:23
0
Setup a method that gets fired with the performSelector:withObject:afterDelay: call:
-(void)performTheseAction {
// do something
// do something else
[self callAnotherMethod];
[self whyNotCallAnotherMethod];
}

runmad
- 14,846
- 9
- 99
- 140