11-19-2009, 08:35 PM
#1 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
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
11-19-2009, 08:42 PM
#2 (permalink )
Beast Iphone Developor
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
Quote:
Originally Posted by
ShayansMind
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
}
11-19-2009, 08:43 PM
#3 (permalink )
Web & Software Developer
Join Date: Nov 2009
Posts: 94
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
11-19-2009, 08:43 PM
#4 (permalink )
Beast Iphone Developor
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
Quote:
Originally Posted by
RyanW
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
11-19-2009, 08:48 PM
#5 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Hmmmm..
Quote:
Originally Posted by
justill45
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
11-19-2009, 08:53 PM
#6 (permalink )
Web & Software Developer
Join Date: Nov 2009
Posts: 94
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.
11-19-2009, 08:53 PM
#7 (permalink )
Will Work for Food!
Join Date: Apr 2009
Posts: 579
Quote:
Originally Posted by
ShayansMind
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;
}
}
11-20-2009, 12:37 AM
#8 (permalink )
Registered Member
Join Date: Nov 2009
Location: Orange County, California
Posts: 36
Quote:
Originally Posted by
itzdark
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 fileURLWithPath
ath] 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
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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