Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2009, 04:07 AM   #1 (permalink)
Registered Member
 
cartz's Avatar
 
Join Date: Aug 2009
Posts: 12
cartz is on a distinguished road
Default Problem with UIButton events and timer

Hello,

On screen I have a numerical value and two buttons. One button increments this value when held and stops incrementing when released. The other button does the same but decreases the value. The 'touch down' events of the buttons kicks off an NSTimer to run the code that will increase / decrease the value. The 'touch up inside' events invalidate the timer.

My problem is that when the button is pressed and held but the user slides their finger away to another part of the screen and then releases it the timer doesn't stop and the values increase or decrease indefinitely (press the button again doesn't help).

I tried having the 'touch up outside' link to the same IBAction code as the 'touch up inside' but this hangs the application.

Here is my 'touch down' code for an increase:

- (IBAction)touchDownIncrease:(id)sender;
{
timerIncrease = [[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(holdForIncrease) userInfo:nil repeats:YES] retain];
}

Here is my 'touch up inside' code for an increase:

- (IBAction)touchUpIncrease:(id)sender;
{
if ([timerIncrease isValid]) {
[timerIncrease invalidate];
[timerIncrease release];
}
}

Can someone please point me in the right direction.

Thanks,

cartz.

PS. Is there a good description anywhere of the various button events, I just can't seem to find it.
cartz is offline   Reply With Quote
Old 08-10-2009, 06:06 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 459
NewiPhoneDeveloper is on a distinguished road
Default

Quote:
Originally Posted by cartz View Post
Hello,

On screen I have a numerical value and two buttons. One button increments this value when held and stops incrementing when released. The other button does the same but decreases the value. The 'touch down' events of the buttons kicks off an NSTimer to run the code that will increase / decrease the value. The 'touch up inside' events invalidate the timer.

My problem is that when the button is pressed and held but the user slides their finger away to another part of the screen and then releases it the timer doesn't stop and the values increase or decrease indefinitely (press the button again doesn't help).

I tried having the 'touch up outside' link to the same IBAction code as the 'touch up inside' but this hangs the application.

Here is my 'touch down' code for an increase:

- (IBAction)touchDownIncreaseid)sender;
{
timerIncrease = [[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(holdForIncrease) userInfo:nil repeats:YES] retain];
}

Here is my 'touch up inside' code for an increase:

- (IBAction)touchUpIncreaseid)sender;
{
if ([timerIncrease isValid]) {
[timerIncrease invalidate];
[timerIncrease release];
}
}

Can someone please point me in the right direction.

Thanks,

cartz.

PS. Is there a good description anywhere of the various button events, I just can't seem to find it.
I guess you need TouchUpOutside. Create an action, like below and connect it to the touchUpOutside event.

Code:
- (IBAction)touchUpOutside:(id)sender;
{
	if ([timerIncrease isValid]) {
            [timerIncrease invalidate];
            timerIncrease = nil;
	    [timerIncrease release];
	}
}
Hope, this helps...
__________________
Websites:
Friendlydeveloper - Coding Blog
Codingsessions - Live iOS Training

iPhone Apps:
TextPal - Powerful group messaging,
icePhone

Find me on LinkedIn
NewiPhoneDeveloper is offline   Reply With Quote
Old 08-10-2009, 06:18 AM   #3 (permalink)
Registered Member
 
cartz's Avatar
 
Join Date: Aug 2009
Posts: 12
cartz is on a distinguished road
Default

Quote:
Originally Posted by NewiPhoneDeveloper View Post
I guess you need TouchUpOutside.
Brilliant - that worked. Thanks heaps. I should have tried that myself but I assumed that my attaching the same IBAction to different button events would have achieved the same result. That'll teach me to assume.

Cheers
cartz is offline   Reply With Quote
Reply

Bookmarks

Tags
nstimer, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 313
12 members and 301 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0