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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 11-19-2009, 08:35 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default Double Click Button

Hello, I was wondering is there a code where i can click a uibutton and start an action and then click the same button to stop the action

Help Please
ShayansMind is offline   Reply With Quote
Old 11-19-2009, 08:42 PM   #2 (permalink)
Beast Iphone Developor
 
justill45's Avatar
 
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
Default

Quote:
Originally Posted by ShayansMind View Post
Hello, I was wondering is there a code where i can click a uibutton and start an action and then click the same button to stop the action

Help Please
well, heres what i thought of off the top of my head, in your .h make an int equal to 1

Then, in your .m under your button write:

if ( yourInt == 1 )
{
// code to make it play
}
else if ( yourInt == 2)
{
//code to make it stop playing
yourInt = 1
}
justill45 is offline   Reply With Quote
Old 11-19-2009, 08:43 PM   #3 (permalink)
Web & Software Developer
 
Join Date: Nov 2009
Posts: 94
Default

Never mind, seems while I was typing a reply, the guy above me said almost the same thing

Last edited by RyanW; 11-19-2009 at 08:44 PM. Reason: hmm
RyanW is offline   Reply With Quote
Old 11-19-2009, 08:43 PM   #4 (permalink)
Beast Iphone Developor
 
justill45's Avatar
 
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
Default

Quote:
Originally Posted by RyanW View Post
You could say button pressed = 1, and have the action of the button pressed say :
Code:
if(button pressed == 1) {
execute code
button pressed = 2;
}
Then you could say
Code:
 if(button presses == 20 {
code to end it
button pressed = 1;
}
lol, we posted the same exact code at the same exact time
justill45 is offline   Reply With Quote
Old 11-19-2009, 08:48 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default Hmmmm..

Quote:
Originally Posted by justill45 View Post
lol, we posted the same exact code at the same exact time
Ok, ill try it but i want to lay a sound with a button then stop it with the same button .... i know the sound code but how can i make it work
ShayansMind is offline   Reply With Quote
Old 11-19-2009, 08:53 PM   #6 (permalink)
Web & Software Developer
 
Join Date: Nov 2009
Posts: 94
Default

define pressed = 1 in the header file, then
Code:
if(pressed == 1) {
execute code to start
pressed = 2;
}
Then you could say
Code:
 if(pressed == 2 {
code to end the sound
pressed = 1;
}
You would put those in the same action, and connect that to the button.
RyanW is offline   Reply With Quote
Old 11-19-2009, 08:53 PM   #7 (permalink)
Will Work for Food!
 
itzdark's Avatar
 
Join Date: Apr 2009
Posts: 579
Send a message via AIM to itzdark Send a message via MSN to itzdark
Default

Quote:
Originally Posted by ShayansMind View Post
Ok, ill try it but i want to lay a sound with a button then stop it with the same button .... i know the sound code but how can i make it work
Code:
BOOL actionIsOn;

- (IBAction)myButtonMethod 
{

if(actionIsOn)
{
//the action was on, lets stop it
actionIsOn = FALSE;
} else {
//the action was off, lets start it
actionIsOn = TRUE;
}

}
__________________

Check out my apps

Developers, check out study buddy. I use it everytime I code. It's great for those late night coding sessions.
Unofficial Ad Hoc Distribution Guide || Join my cooperative ad hoc testing group
iSoothe Promotional Video
Contact Me
itzdark is offline   Reply With Quote
Old 11-20-2009, 12:37 AM   #8 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Send a message via AIM to ShayansMind Send a message via Skype™ to ShayansMind
Default

Quote:
Originally Posted by itzdark View Post
Code:
BOOL actionIsOn;

- (IBAction)myButtonMethod 
{

if(actionIsOn)
{
//the action was on, lets stop it
actionIsOn = FALSE;
} else {
//the action was off, lets start it
actionIsOn = TRUE;
}

}

I tried it it didn't work
- (IBAction)myButton {

if(actionIsOn)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"anthem" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
theAudio.delegate = self;
[theAudio play];

//the action was on, lets stop it
actionIsOn = FALSE;
} else {
//the action was off, lets start it
actionIsOn = TRUE;
}

}
HELP
ShayansMind is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, sdk, 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: 244
18 members and 226 guests
ADY, Alsahir, beleg_1998, Dani77, diyora, iDifferent, iph_s, JamesCahall, JasonR, mer10, Monstertaco, prchn4christ, Robiwan, Rudy, smithdale87, Speed, spiderguy84, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,755
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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