i am pretty much a noob here , and even writing the title was pretty hard …but here goes
I am trying to get my app to do this
1) user presses a button
2) the button converts the press to an int value
3) the value is then passed to NStimer and the timer counts until the int value is reached ( ie 30 secs if int value is 30
4) the program changes the image on the screen
I have got it to fire off the NStimer and change the screen by using a variable button and by changing this value manually i can set the timer to go off after different times
What i cant do is to get the timer to fire after the value is changed by the pressing of the button.
If i use NSLog i can see the value is changing but doesnt affect NSTimer….any ideas
Sorry if thats a bit long winded ,but here is the code…
Any help would be awesome…as i have lost most of my hair trying to work this out with do while loops and if statements
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIImageView *theImage;
int imageCount;
int button;
button = 10;
}
@property (strong, nonatomic) IBOutlet UIImageView *theImage;
@property (strong, nonatomic) IBOutlet UIButton *press;
@end
//
// ViewController.m
// use ns timer to display an image
//
// Created by Clive Dancey on 19/02/2013.
// Copyright (c) 2013 Clive Dancey. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UILabel *label1;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:button
target:self
selector:@selector(animateFunction)
userInfo:nil
repeats:YES];
}
- (IBAction)press:(id)sender
{
button = 1;
}
- (void)animateFunction
{
NSLog(@"Timer heartbeat %i", button);
NSString *imageName = [NSString stringWithFormat:@"EZDecline.png"];
[_theImage setImage:[UIImage imageNamed:imageName]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Ok I got you,
1) remove this from viewDidLoad
2) Add this line to .h file
3) Change the code in your button press event, (like this)
}