Search Results

Search found 152 results on 7 pages for 'nstimer'.

Page 2/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Accessing Instance Variables from NSTimer selector

    - by Timbo
    Firstly newbie question: What's the difference between a selector and a method? Secondly newbie question (who would have thought): I need to loop some code based on instance variables and pause between loops until some condition (of course based on instance variables) is met. I've looked at sleep, I've looked at NSThread. In both discussions working through those options many asked why don't I use NSTimer, so here I am. Ok so it's simple enough to get a method (selector? ) to fire on a schedule. Problem I have is that I don't know how to see instance variables I've set up outside the timer from within the code NSTimer fires. I need to see those variables from the NSTimer selector code as I 1) will be updating their values and 2) will set labels based on those values. Here's some code that shows the concept… eventually I'd invalidate the timers based on myVariable too, however I've excluded that for code clarity. MyClass *aMyClassInstance = [MyClass new]; [aMyClassInstance setMyVariable:0]; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doStuff) userInfo:nil repeats:YES]; [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(doSomeOtherStuff) userInfo:nil repeats:YES]; - (void) doStuff { [aMyClassInstance setMyVariable:11]; // don't actually have access to set aMyClassInstance.myVariable [self updateSomeUILabel:[NSNumber numberWithInt:aMyClassInstance.myVariable]]; // don't actually have access to aMyClassInstance.myVariable } - (void) doSomeOtherStuff { [aMyClassInstance setMyVariable:22]; // don't actually have access to set aMyClassInstance.myVariable [self updateSomeUILabel:[NSNumber numberWithInt:aMyClassInstance.myVariable]]; // don't actually have access to aMyClassInstance.myVariable } - (void) updateSomeUILabel:(NSNumber *)arg{ int value = [arg intValue]; someUILabel.text = [NSString stringWithFormat:@"myVariable = %d", value]; // Updates the UI with new instance variable values }

    Read the article

  • Timer (NSTimer) won't work...why?

    - by eco_bach
    Hi I have the following, can anyone familiar with NSTimer tell me why it isn't working?? I've tried various values for an interval but no luck. self.timer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(update:) userInfo:nil repeats:YES]; And then my selector method - (void)update:(NSTimer*)timer { //DOESN"T TRACE OUT! NSLog(@" update:theTimer and userInfo = %@",timer.userInfo); }

    Read the article

  • Why am I getting a EXC_BAD_ACCESS in a NSTimer selector?

    - by AngeDeLaMort
    I've got quite a weird problem. To make it short, i'll write some pseudo-code: init: create a dictionary and insert n elements. create a "repeat timer" and add it to the currentRunLoop using the timerRefresh selector. timerRefresh: using a list of keys, find the items in the dictionary if the item exists -> call a function So, for an unknown reason, I get an EXC_BAD_ACCESS when I do: [item function]; But I traced the address I got from the dictionary items and it's ok. The ref count of the items in the dictionary is still 1. The {release, dealloc} of the items in the dictionary aren't called. Everything seems fine. Also, to make it worst, it works for some items. So, I'm wondering if there is a threading problem? or something else obscure? The callstack is quite simple: #0 0x93e0604b in objc_msgSend_fpret #1 0x00f3e6b0 in ?? #2 0x0001cfca in -[myObject functionm:] at myObject.m:000 #3 0x305355cd in __NSFireTimer #4 0x302454a0 in CFRunLoopRunSpecific #5 0x30244628 in CFRunLoopRunInMode #6 0x32044c31 in GSEventRunModal #7 0x32044cf6 in GSEventRun #8 0x309021ee in UIApplicationMain #9 0x000027e0 in main at main.m:14 So, any suggestion where to look would be appreciated.

    Read the article

  • Is it possible to make an alarm using NSTimer and UIDatepicker?

    - by user557425
    I have an app which plays some ambient noises. I have fitted it with a sleep timer and a local notifier which work fine, but the notifier will only fire when the app is in the background. I would like to be able to fit a standard alarm clock that the user can set using the date picker, ie, the user picks 07:15 am on the date picker and this triggers a sound being played at this time. Can this be done?

    Read the article

  • Change NSTimer interval for repeating timer.

    - by user300713
    Hi, I am running a mainLoop in Cocoa using an NSTimer set up like this: mainLoopTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/fps target:self selector:@selector(mainloop) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:mainLoopTimer forMode:NSEventTrackingRunLoopMode]; At Program startup I set the timeInterval to 0.0 so that the mainloop runs as fast as possible. Anyways, I would like to provide a function to set the framerate(and thus the time interval of the timer) to a specific value at runtime. Unfortunately as far as I know that means that I have to reinitialize the timer since Cocoa does not provide a function like "setTimerInterval" This is what I tried: - (void)setFrameRate:(float)aFps { NSLog(@"setFrameRate"); [mainLoopTimer invalidate]; mainLoopTimer = nil; mainLoopTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/aFps target:self selector:@selector(mainloop) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:mainLoopTimer forMode:NSEventTrackingRunLoopMode]; } but this throws the following error and stops the mainloop: 2010-06-09 11:14:15.868 myTarget[7313:a0f] setFrameRate 2010-06-09 11:14:15.868 myTarget[7313:a0f] * __NSAutoreleaseNoPool(): Object 0x40cd80 of class __NSCFDate autoreleased with no pool in place - just leaking 2010-06-09 11:14:15.869 myTarget[7313:a0f] * __NSAutoreleaseNoPool(): Object 0x40e700 of class NSCFTimer autoreleased with no pool in place - just leaking 0.614628 I also tried to recreate the timer using the "retain" keyword, but that didn't change anything. Any ideas about how to dynamically change the interval of an NSTimer at runtime? Thanks!

    Read the article

  • Making alarm clock with NSTimer

    - by Alex G
    I just went through trying to make an alarm clock app with local notifications but that didn't do the trick because I needed an alert to appear instead of it going into notification centre in iOS 5+ So far I've been struggling greatly with nstimer and its functions so I was wondering if anyone could help out. I want when the user selects a time (through UIDatePicker, only time) for an alert to be displayed at exactly this time. I have figured out how to get the time from UIDatePicker but I do not know how to properly set the firing function of nstimer. This is what I have attempted so far, if anyone could help... be much appreciated. Thank you Example (it keeps going into the function every second opposed to a certain time I told it too... not what I want): NSDate *timestamp; NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease]; [comps setHour:2]; [comps setMinute:8]; timestamp = [[NSCalendar currentCalendar] dateFromComponents:comps]; NSTimer *f = [[NSTimer alloc] initWithFireDate:timestamp interval:0 target:self selector:@selector(test) userInfo:nil repeats:YES]; NSRunLoop *runner = [NSRunLoop currentRunLoop]; [runner addTimer:f forMode: NSDefaultRunLoopMode];

    Read the article

  • converting NSTimer running not on main runloop to GCD

    - by Justin Galzic
    I have a task that runs periodically and it was originally designed to run on a separate run loop than the main runloop using NSThread and NSTimer. What's the best way to adapt this to take advantage of GCD? Current code: -(void)initiateSomeTask { [NSThread detachNewThreadSelector:@selector(startTimerTask) toTarget:self withObject:nil]; } -(void)startTimerTask { // We won't get back the main runloop since we're on a new thread NSRunLoop *myRunLoop = [NSRunLoop currentRunLoop]; NSPort *myPort = [NSMachPort port]; [myRunLoop addPort:myPort forMode:NSDefaultRunLoopMode]; NSTimer *myTimer = [NSTimer timerWithTimeInterval:10 /* seconds */ target:self selector:@selector(doMyTaskMethod) userInfo:nil repeats:YES]; [myRunLoop addTimer:myTimer forMode:NSRunLoopCommonModes]; [myRunLoop run]; } Is there anything I can do besides replace detachNewThreadSelector with dispatch_async?

    Read the article

  • Quartz 2D's drawing text and NSTimer in custom method

    - by coure06
    i want to show text using quartz 2d. Text will be drawing randomly on different position after each 1 seconds. I am not sure how i can use NSTimer with quartz 2D text. I can draw text in drawRect method where graphics context is already available. How i will draw text using my custom method myDraw which will be called after 1 second using NSTimer? If i create my custom Method the graphics context is not available in that method.

    Read the article

  • passing uiimageview as a parameter in NStimer selector??

    - by hemant
    i created a function onTimer passing it a uiimageview parameter...but when i call this function in a NStimer call as shown below i get a syntax error?? is there any other way around it?? [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer:image) userInfo:nil repeats:YES];

    Read the article

  • [Cocoa] Placing an NSTimer in a separate thread

    - by ndg
    I'm trying to setup an NSTimer in a separate thread so that it continues to fire when users interact with the UI of my application. This seems to work, but Leaks reports a number of issues - and I believe I've narrowed it down to my timer code. Currently what's happening is that updateTimer tries to access an NSArrayController (timersController) which is bound to an NSTableView in my applications interface. From there, I grab the first selected row and alter its timeSpent column. From reading around, I believe what I should be trying to do is execute the updateTimer function on the main thread, rather than in my timers secondary thread. I'm posting here in the hopes that someone with more experience can tell me if that's the only thing I'm doing wrong. Having read Apple's documentation on Threading, I've found it an overwhelmingly large subject area. NSThread *timerThread = [[[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil] autorelease]; [timerThread start]; -(void)startTimerThread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; activeTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES] retain]; [runLoop run]; [pool release]; } -(void)updateTimer:(NSTimer *)timer { NSArray *selectedTimers = [timersController selectedObjects]; id selectedTimer = [selectedTimers objectAtIndex:0]; NSNumber *currentTimeSpent = [selectedTimer timeSpent]; [selectedTimer setValue:[NSNumber numberWithInt:[currentTimeSpent intValue]+1] forKey:@"timeSpent"]; } -(void)stopTimer { [activeTimer invalidate]; [activeTimer release]; }

    Read the article

  • Change UIButton Background Image more than once per second

    - by beta.services
    I am currently working with the iPhone SDK. I have a NSTimer that changes the background image of a UIButton. Once this is complete, it will trigger the same action again (reset the NSTimer) for a predetermined number of times. My problem is that if my NSTimer is set to execute more than once per second. (0.75, say) The background image wont change. I am using NSLog to check that the event fires. But the button image will just remain in its original state. Is there any way to change the background image more often than once per second? This is my timer : [NSTimer scheduledTimerWithTimeInterval: tmpLvlSpeed target: self selector: @selector(simPressRed:) userInfo: nil repeats: NO]; And the code to change the image: [btnRed setImage:[UIImage imageNamed:@"btn_red.png"] forState:UIControlStateNormal]; if tmpLvlSpeed is less than 1.0, the button image will never change. Even though the simPressRed function will still fire. Any clues? Is there an update cycle I can modify?

    Read the article

  • Change NSButton Background Image more than once per second

    - by beta
    I am currently working with the iPhone SDK. I have a NSTimer that changes the background image of a NSButton. Once this is complete, it will trigger the same action again (reset the NSTimer) for a predetermined number of times. My problem is that if my NSTimer is set to execute more than once per second. (0.75, say) The background image wont change. I am using NSLog to check that the event fires. But the button image will just remain in its original state. Is there any way to change the background image more often than once per second? Thanks.

    Read the article

  • Using Quartz to draw every second via NSTimer (iPhone)

    - by stuartloxton
    Hi, I'm relatively new to Objective-C + Quartz and am running into what is probably a very simple issue. I have a custom UIView sub class which I am using to draw simple rectangles via Quartz. However I am trying to hook up an NSTimer so that it draws a new object every second, the below code will draw the first rectangle but will never draw again. The function is being called (the NSLog is run) but nothing is draw. Code: - (void)drawRect:(CGRect)rect { context = UIGraphicsGetCurrentContext(); [self step:self]; [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)(2) target:self selector:@selector(step:) userInfo:nil repeats:TRUE]; } - (void) step:(id) sender { static double trans = 0.5f; CGContextSetRGBFillColor(context, 1, 0, 0, trans); CGContextAddRect(context, CGRectMake(10, 10, 10, 10)); CGContextFillPath(context); NSLog(@"Trans: %f", trans); trans += 0.01; } context is in my interface file as: CGContextRef context; Any help will be greatly appreciated!

    Read the article

  • NSTimer as Alarm

    - by huntaub
    Is the best practice of setting an alarm on OS X to create a NSTimer scheduled for the number of seconds between the current time and the desired time for the alarm, or is there an alternative to that method?

    Read the article

  • difference among NSthread and NStimer and NSNotifcation?

    - by senthilmuthu
    What is the difference among following codes 1) [NSThread detachNewThreadSelector:@selector(myFunction) toTarget:self withObject:thename]; 2) [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(myFunction:) userInfo:nil repeats:NO]; 3) [self performSelector:@selector(myFunction) withObject:nil afterDelay:myDelay]; 4) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunction:) name:thename object:nil];

    Read the article

  • Why need to call NSTimer again in this code?

    - by Tattat
    - (void) applicationDidFinishLaunching:(UIApplication *)application { //set up main loop [NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(gameLoop:) userInfo:nil repeats:NO]; //create instance of the first GameState [self doStateChange:[gsMain class]]; } - (void) gameLoop: (id) sender { [((GameState*)viewController.view) Update]; [((GameState*)viewController.view) Render]; [NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(gameLoop:) userInfo:nil repeats:NO]; } This code is from a iPhone game development book. I don't know why the gameLoop method need to call the NSTimer again? in the applicationDidFinishLaunching, it set the NSTimer to do, why don't let it do every 0.033s, why add the same NSTimer code in the gameLoop method? thz.

    Read the article

  • How do I reset a countdown timer when it reaches 0? (Xcode 4)

    - by Zac Prunty
    first question and I have researched the heck out of this and can't seem to find any answers. I would like to implement a countdown timer in my app that starts at 30 seconds and resets when it hits 0. It will count back by 1 second intervals. I have played around with the resources that Apple provides and I can't seem to implement the NStimer to do as I just explained. Are there any suggestions on how I could code this? I would eventually like to link this to a button that will start the timer when it is pressed. I appreciate any advice on this topic!

    Read the article

  • Why when I render a scene with a revolving camera objects that you'd expect to appear behind others

    - by seaworthy
    Hello, I am rendering a scene in which I have two spheres. I am revolving a camera around one of them. What happens is counter-intuitive. When the camera goes around the sphere the other gets in front of it when you'd expect it to be behind. So it appears as though the spheres aren't revolving around each other and the one the should go around is always upfront. Please help. Here is the code that renders the scene: glLoadIdentity(); [self positionCamera]; glutSolidSphere(2, 12,12); glPushMatrix(); glTranslatef(5, 0, 0); glutSolidSphere(0.5, 12,12); glPopMatrix(); glFlush(); This block is part of a class that gets called on using. [NSTimer scheduledTimerWithTimeInterval:DEFAULT_ANIMATION_INTERVAL target:self selector:@selector(drawRect) userInfo:nil repeats:YES]; And -(void)positionCamera{} Contains math do camera revolution and gluLookAt()

    Read the article

  • Timeout a NSThread after a certain amount of time

    - by Zen_silence
    Hello, I have a NSThread that i would like to timeout after a certain amount of time. [NSThread detachNewThreadSelector:@selector(someFuntion) toTarget:self withObject:nil]; - (void) someFunction { //Some calculation that might take a long time. //if it takes more then 10 seconds i want it to end and display a error message } Any help you can provide on this would be greatly appreciated. Thanks, Zen_silence

    Read the article

  • How to make UIButton work like Launcher in SpringBoard, when pressed for long timeinterval

    - by KayKay
    In my ViewController I am using UIButton which triggers some action when touchedUpInside. Upto here no problem, but i also want to add another action for touchDown event. More precisely i dont have an idea how to add that action to which event, that will work the same as when App-Icon is pressed longer in springboard which causes springboard enter in editing mode.Actually what i want is : when this button is kept holding for ,say about 2 seconds it will pop-up an alertView without touch being heldUp (with finger is still on button). I have tried with 2 NSdate difference, one of which is allocated when touchedDown and other when touchUpInside. Its working and popping alert,but only after touchedUpInside. I want it to show alert without touch being removed. Here is the code. (IBAction)touchedDown:(id)sender { momentTouchedDown = [[NSDate alloc] init];//class variable NSLog(@"touched down"); } - (IBAction)touchUpInside:(id)sender { NSLog(@"touch lifted Up\n"); NSDate *momentLifted = [[NSDate alloc] init]; double timeInterval = [momentLifted timeIntervalSinceDate:momentTouchedDown]; NSLog(@"time lifted = %@, time down = %@, time diff = %@", momentLifted, momentTouchedDown, [NSString stringWithFormat:@"%g",timeInterval]); [momentLifted release]; if(timeInterval > 2.0) { NSLog(@"AlertBox has been fired"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yes" message:@""//msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK" , nil]; [alert show]; [alert release]; } } Please provide me an insight..thanks for help in advance.

    Read the article

  • "Multi-threading" w/ NSTimers in an iPhone app

    - by MrDatabase
    Say I have two NSTimers in my iPhone app: timer1 and timer2. timer1 calls function1 30 times per second and timer2 calls function2 30 times per second. Assume these two functions are reading and updating the same integer variables. Are there any "multi-threading" issues here? If not how does iPhone OS handle the execution of the two functions (in general)?

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >