cancelPreviousPerformRequestsWithTarget - iphone

cancelPreviousPerformRequestsWithTarget is not working for me, i checked every one saying its working fine but for me not
i call the following in performselector
[self performSelector:#selector(Opacity:) withObject:self.objopcarray afterDelay:reversedelay];
now i want to cancel it on a button click before it fires so i did the following
- (void) pressNextButton:(id)sender
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(Opacity:) object:self.objopcarray];
if (self.animationON == YES)
{
if (self.panel < 16)
{
[self DisplayImages];
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:sketchanimduration target:self selector:#selector(DisplayImages) userInfo:nil repeats:YES];
if(self.panel > 16)
{
self.panel = 0;
}
}
}
}
but still same result
any help will be highly appreciated

Related

progress bar not showing the step by step progress in iphone

Hi all im using progress bar for indicating the status of xml parsing in my app.but it is not showing the step by step updation,instead the progress bar is loading after the entire xml parsing is over,till that time it is stuck and not showing any progress.how to solve this issue.can anyone help me please.
I use the below code
IBOutlet UIProgressView * threadProgressView;
threadProgressView.progress = 0.0;
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
- (void)makeMyProgressBarMoving
{
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
else{
/* something else */
}
}
Create a timer on the main thread for every 1/10th of a second. Have it hit your "makeMyProgressBarMoving" function.
myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:YES];
Then edit your function to look like this:
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
return;
}
//if you got here that means the progress view is greater than 1 so now you can kill your timer that you had running every 1/10th of a second.
[myTimer invalidate];
}

iOS Camera Countdown Timer

I'm looking for the cleanest way to have a countdown timer fire when a user hits the 'take picture' button. Is there any easy way to do this?
One solution I'm thinking of is to just have a label that updates every second, but is there a way to get it working like Photobooth?
Also, at the last second before the photo is about to be taken I'd like for an image to be displayed briefly while the image is being taken. How can I go about this?
Any help would be great, thanks!
- (IBAction)takePicture:(id)sender {
theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
- (void)updateLabel:(NSTimer *)timer {
_timeLabel.text = [NSString stringWithFormat:#"%d", time];
time = time - 1;
if (time == 0) {
[theTimer invalidate];
[_timeLabel performSelector:#selector(setText:) withObject:#"Photo taken!" afterDelay:1.0];
//Code for image shown at last second
} else {
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
}
Hope this helps ;)

iPhone Timer - How to wait seconds?

I'm trying to wait seconds ..
for (int i = 0; i < 3; i++) {
// something A
...
// wating
[NSTimer scheduledTimerWithTimeInterval:10
target:self
selector:#selector(endTimer:)
userInfo:nil
repeats:YES];
// something B
...
}
- (void)endTimer:(NSTimer *)timer {
NSLog(#"end timer");
[timer invalidate];
}
I wanna 'A -> waiting -> B'
but don't wait ...
A -> B -> A -> B -> A -> B -> end timer, end timer, end timer
Is there any way?
good day
try this,
-(void)callA{
//Do your thing...
}
-(void)callB{
//Do your thing...
}
-(void)callFunction{
count++;
if(count<3){
[self performSelector:#select(callA) withObject:nil];
[NSThread sleepForTimeInterval:3.0];
[self callB];
}
else{
[timer invalidate];
}
}
Now, create timer in main function from which you want to call the above function.
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(callFunction) userInfo:nil repeats:YES];
Even if your question is not phrased well,
// set myCount somewhere as an INT with value 0
// int myCount = 0;
-(void)callA
{
if (myCount < 3){
[self performSelector:#selector(callB) withObject:nil afterDelay:1.0];
}
}
-(void)callB
{
myCount +=1;
[self performSelector:#selector(callA) withObject:nil afterDelay:1.0];
}

run timer automatically for first and second time

I am new to iPhone,
What I want is that my timer call a function every second but for the very first time it must call the function at 2 second.
Any help will be really appreciated. Thanks
take a variable
BOOL isNotFirstTime;
And in the function that gets triggered after each 4 secs add the following code at the starting
-(void)AfterOneSecondsFuction
{
if(!isNotFirstTime)
{
isNotFirstTime=YES;
return;
}
//YOUR CODE HERE...
}
This is how you give a call to the function
NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(AfterOneSecondsFuction) userInfo:nil repeats:YES];
First schedule a timer and have a BOOL variable say isFirstTime set as YES;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doSomething) userInfo:nil repeats:YES];
and in
- (void)doSomething
{
if(isFirstTime)
{
isFirstTime = NO;
return;
}
// Do something
}

NStimer and for loop

I'm struggling with this. I saw some code where you can do this :
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
Then call it in doActions.
Problem is i want to call it while a button is being pressed, and do actions is an IBaction. I keep getting a sigAbrt.
Can someone give me some sample code where you cay change a label from 'on' to 'off' every 1 second while a button is being pressed?
EDIT
i mean if doActions looks like this
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
It still isn't clear to me, what you're trying to accomplish: I would have found it much easier, if you simply had it written down in plain english, after all.
That said, here's what I think will get you where you want to go:
// Assuming ivars:
// NSTimer* toggleTimer
// NSUInteger toggleCount
- (void)toggleTimerFired:(NSTimer*)timer
{
if ( toggleCount++ >= 100 ) {
[self stopToggling:self];
return;
}
// do whatever you need to do a hundred times here
}
- (IBAction)stopToggling:(id)sender
{
[toggleTimer invalidate], toggleTimer = nil; // you don't want dangling pointers...
// perform any other needed house-keeping here
}
- (IBAction)startToggling:(id)sender
{
[self stopToggling:self]; // if `startToggling:` will NEVER be called when a timer exists, this line CAN be omitted.
toggleCount = 0;
toggleTimer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:#selector(toggleTimerFired:) userInfo:nil repeats:YES];
}
Depending on what exactly you want to do, startToggling: needs to be sent on either touchUpInside or touchDown. In the second case, stopToggling: probably needs to be called on any touchUp... event of the button.
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
- (void) doActions {
theLabel.hidden != theLabel.hidden;
}