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 04-23-2010, 01:50 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default How do you put a (IBAction) inside an "if" statement???

Here is my code
Code:
	
if (row == 0) {
		
- (IBAction)go {
			
}
		
}
When I try to run it I get this error,
Code:
error: 'go' undeclared (first use in this function)
error: expected ';' before '{' token
But when I move the IBAction code outside of the if statement everything builds fine. What am I doing wrong?!!?!?!?

Thanks in advanced!
tackey123 is offline   Reply With Quote
Old 04-23-2010, 01:58 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 211
csnplt is on a distinguished road
Default

Quote:
Originally Posted by tackey123 View Post
Here is my code
Code:
	
if (row == 0) {
		
- (IBAction)go {
			
}
		
}
When I try to run it I get this error,
Code:
error: 'go' undeclared (first use in this function)
error: expected ';' before '{' token
But when I move the IBAction code outside of the if statement everything builds fine. What am I doing wrong?!!?!?!?

Thanks in advanced!
I think you are misunderstanding how this works. Declare your method somewhere in your file, and then do something like this:

Code:
-(IBAction)myIBActionMethod
{
      //Do something here
}

-(void)didSelectRowAtIndexPath: ...
{
     if(row == 0)
     {
           [self myIBActionMethod];
     }

}
__________________
www.thomashuntington.com

Political GPS - Track your Congress and Find Yourself.
Apple New and Noteworthy

Nightstand Central - Music Alarm Clock with Weather, Photos, and Sleep Timer
Apple Staff Favorite - Top 10 iPhone Paid Productivity, Top 5 Free iPad Overall
csnplt is offline   Reply With Quote
Old 04-23-2010, 02:06 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by csnplt View Post
I think you are misunderstanding how this works. Declare your method somewhere in your file, and then do something like this:

Code:
-(IBAction)myIBActionMethod
{
      //Do something here
}

-(void)didSelectRowAtIndexPath: ...
{
     if(row == 0)
     {
           [self myIBActionMethod];
     }

}
No, what I am trying to do is make it so the button doesn't do anything when you click on it until the "if" statement is true.
tackey123 is offline   Reply With Quote
Old 04-23-2010, 02:17 PM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 211
csnplt is on a distinguished road
Default

Quote:
Originally Posted by tackey123 View Post
No, what I am trying to do is make it so the button doesn't do anything when you click on it until the "if" statement is true.
I see. Do something like this:

Code:
-(IBAction)myIBActionMethod
{
     //Do something here
}

if(row == 0)
{
     [self myIBActionMethod];
}
__________________
www.thomashuntington.com

Political GPS - Track your Congress and Find Yourself.
Apple New and Noteworthy

Nightstand Central - Music Alarm Clock with Weather, Photos, and Sleep Timer
Apple Staff Favorite - Top 10 iPhone Paid Productivity, Top 5 Free iPad Overall
csnplt is offline   Reply With Quote
Old 04-23-2010, 02:29 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by csnplt View Post
I see. Do something like this:

Code:
-(IBAction)myIBActionMethod
{
     //Do something here
}

if(row == 0)
{
     [self myIBActionMethod];
}
No still not right.

What I am trying to do is something similar to the app iFart, it has a scroll wheel and you choose what sound you want them press a button and it plays.

Here is where the problem is:

Code:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	

	
	if (row == 1) {
		
		- (IBAction)go {
			
			//do someting
			
		}
		
	}
	
	
	
	
}
tackey123 is offline   Reply With Quote
Old 04-23-2010, 02:32 PM   #6 (permalink)
So cunning its ridiculous
 
Join Date: Apr 2009
Age: 17
Posts: 135
CunningCat is on a distinguished road
Default

why don't you put inside the IBAction an if statement seeing if it is the correct row and if it isn't just don't do anything
__________________
CunningCat
www.bigblueapps.webs.com
Baby Age Calulator
CunningCat is offline   Reply With Quote
Old 04-23-2010, 02:40 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by CunningCat View Post
why don't you put inside the IBAction an if statement seeing if it is the correct row and if it isn't just don't do anything
I tried that:

Code:
- (IBAction)fart {
	
	
	if (row == 1) {
		
		
		
	}
	
	
	
}
But I get this error:
Code:
error: 'row' undeclared (first use in this functions)
tackey123 is offline   Reply With Quote
Old 04-23-2010, 02:42 PM   #8 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

I think this is the code you want:

Code:
- (void)go1 {
			
			//do someting
			
}


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	

	
	if (row == 1) {
		
		[self go1];
		
	}
	
	
	
	
}
HTH
rocotilos is offline   Reply With Quote
Old 04-23-2010, 02:48 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
I think this is the code you want:

Code:
- (void)go1 {
			
			//do someting
			
}


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	

	
	if (row == 1) {
		
		[self go1];
		
	}
	
	
	
	
}
HTH
Yes that works, but I can't put an - (IBAction) inside a - (void). I get errors saying undeclared. I guess the question is really, "how do you put a (IBAction) inside a (void)"
tackey123 is offline   Reply With Quote
Old 04-23-2010, 02:56 PM   #10 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

nothing

Last edited by rocotilos; 04-23-2010 at 03:01 PM.
rocotilos is offline   Reply With Quote
Old 04-23-2010, 03:01 PM   #11 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Quote:
What I am trying to do is something similar to the app iFart, it has a scroll wheel and you choose what sound you want them press a button and it plays.
I didn't notice the above sentence.

So basically you need to declare a global variable of int.

Code:
int whatSound = 0;
Then you'd assign whatSound to the value of row. and call the play method based on value of whatSound.

Code:
- (IBAction)go1 {
			
	switch (whatSound) {
             case 0: // do nothing
               break;
             case 1: // play sound 1
               break;
             case 2: // play sound 2
               break;
              default: // do nothing
              break;
       }
			
}


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	

	whatSound = row +1;
		

}
go1 is IBAction connected to the button to play the sound.

HTH

Last edited by rocotilos; 04-23-2010 at 03:04 PM.
rocotilos is offline   Reply With Quote
Old 04-23-2010, 03:01 PM   #12 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
Why do want to put an IBAction inside the void?
It does not work that way.

What event is the IBAction connected to?
The way you have it set up is you select something from the list and it plays a sound, what I want is you have to select a sound from the list then press a button in order for it to play.

The IBAction is connected to a button.
tackey123 is offline   Reply With Quote
Old 04-23-2010, 03:05 PM   #13 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

The code u want is given above your last post.
rocotilos is offline   Reply With Quote
Old 04-23-2010, 03:06 PM   #14 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 3
bkl1989 is on a distinguished road
Default

Quote:
Originally Posted by tackey123 View Post
Yes that works, but I can't put an - (IBAction) inside a - (void). I get errors saying undeclared. I guess the question is really, "how do you put a (IBAction) inside a (void)"
You can't define a function in serial code. If you're having trouble with that concept, you would benefit more from studying the basics than from trying to force your way through an IPhone application. Even if it's mostly interface builder, it's gonna give you hell - try picking up one of the recommended books (listed on a stick in the iphone sdk development forum).
Good luck.
bkl1989 is offline   Reply With Quote
Old 04-23-2010, 03:10 PM   #15 (permalink)
Registered Member
 
Join Date: Sep 2009
Age: 15
Posts: 93
tackey123 is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
I didn't notice the above sentence.

So basically you need to declare a global variable of int.

Code:
int whatSound = 0;
Then you'd assign whatSound to the value of row. and call the play method based on value of whatSound.

Code:
- (IBAction)go1 {
			
	switch (whatSound) {
             case 0: // do nothing
               break;
             case 1: // play sound 1
               break;
             case 2: // play sound 2
               break;
              default: // do nothing
              break;
       }
			
}


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	

	whatSound = row +1;
		

}
go1 is IBAction connected to the button to play the sound.

HTH
YESSSSSS!!!! thats it thanks!
tackey123 is offline   Reply With Quote
Reply

Bookmarks

Tags
"if", help me, interface builder, iphone sdk, xcode

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: 310
20 members and 290 guests
baja_yu, cgokey, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, HowEver, iphonedevshani, jbro, JoeRCruso, mdpauley, n00b, newDev, seokwon lee, SLIC, stanny, Steven.C, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,875
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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