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 05-26-2010, 08:39 AM   #1 (permalink)
Rookie SDK Dev
 
Join Date: May 2010
Location: Under a Bridge
Posts: 2
menphes is on a distinguished road
Question IBAction inside IF statement ...

Hello there ... I'm kind of new to the whole Mac and iPhone Development world so I did read a few books/tutorials around to get the gist of it all. But I have a question which I haven't found and answer to yet: Is it possible for me to call an IBAction into an if statement that is already inside another IBAction? I know it sound confusing so I'm going to try and explain what I'm looking to do.

this is the CadastroViewController.m (which is where I fell my problem is)
Code:
#import "CadastroViewController.h"
#import "CadastroAppDelegate.h"
#import "ListViewController.h"

@implementation CadastroViewController

@synthesize usernameField;
@synthesize passwordField;
@synthesize loginButton;

-(IBAction) login:(id)sender {
	NSString *post = [NSString stringWithFormat:@"user=%@&senha=%@",usernameField.text,passwordField.text];
	NSString *hostStr = @"http://.../verificar.php?";
	hostStr = [hostStr stringByAppendingString:post];
	NSData *dataURL = [NSData dataWithContentsOfURL: [NSURL URLWithString: hostStr]];
	NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
	
	if([serverOutput isEqualToString:@"YES"]) {
		CadastroAppDelegate *delegate = (CadastroAppDelegate *)[[UIApplication sharedApplication] delegate];
		ListViewController *listView = [[ListViewController alloc] initWithNibName:@"ListViewController" bundle:nil];
		[delegate changeView:self.view toView:listView.view];
		[listView release];
	} else {
		UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Erro" message:@"Usuario e/ou Senha incorretos" delegate:self cancelButtonTitle:@"Tentar Novamente" otherButtonTitles: nil, nil];
		[alertsuccess show];
		[alertsuccess release];
	}
}

@end
So OK, this is what I do, I have a login view which get the info posted on the textFields and then sends them to an online Database, the server then sends a YES/NO responde if the user and password is from an administrator. If it's not then it sends a NO and the app shows a UIAlertView with a message. On the other hand if sends a YES response the app should change views to a view with an UIWebView in order to read the info inside the Database.

My question is, is there a way for me to make a swap IBAction and call it when the serverOutput=YES?

Now, the system works, it correctly checks the username and password to see if those are of an administrator, if they aren't the UIAlertView will come up correctly, but if they are to app just closes instead of changing the views.

I have already tried everything I could think of, so any input will be welcome. Thanks in advance!
menphes is offline   Reply With Quote
Old 05-26-2010, 09:16 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Code:
[self theOtherAction:nil];
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 05-26-2010, 11:28 AM   #3 (permalink)
Rookie SDK Dev
 
Join Date: May 2010
Location: Under a Bridge
Posts: 2
menphes is on a distinguished road
Default

You my dear friend are a life saver!

Thank you so much Brian!

Last edited by menphes; 05-26-2010 at 11:39 AM.
menphes is offline   Reply With Quote
Old 05-26-2010, 11:30 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, what you are asking for is not exactly clear.

Calling an IBAction is just like calling any other method. I assumed the sender parameter was throwing you off, so I was just demonstrating that you could provide nil.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
database, ibaction, if-statement, serveroutput

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: 316
11 members and 305 guests
ajay123123, ashaman64, baja_yu, ChrisYates, guusleijsten, HemiMG, newDev, Objective Zero, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,878
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:53 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0