Je crée une application avec fenêtre de connexion. L'application construit avec succès, mais dès que je touche le bouton de connexion, l'application se bloque. :(L'application se bloque. :(
J'ai collé le fichier .m ci-dessous.
Où suis-je faire l'erreur :(
Merci à l'avance :)
#import "AuthViewController.h"
@implementation AuthViewController
@synthesize userName;
@synthesize password;
@synthesize loginbutton;
@synthesize indicator;
- (IBAction) loginButton: (id) sender
{
indicator.hidden = NO;
[indicator startAnimating];
loginbutton.enabled = NO;
// Create the username and password string.
// username and password are the username and password to login with
NSString *postString = [[NSString alloc] initWithFormat:@"username=%@&password=%@",userName, password];
// Package the string in an NSData object
NSData *requestData = [NSData dataWithBytes: [postString UTF8String] length: [postString length]];
// Create the URL request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://localhost/dologin.php"]]; // create the URL request
[request setHTTPMethod: @"POST"]; // you're sending POST data
[request setHTTPBody: requestData]; // apply the post data to be sent
// Call the URL
NSURLResponse *response; // holds the response from the server
NSError *error; // holds any errors
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&error]; // call the URL
/* If the response from the server is a web page, dataReturned will hold the string of the HTML returned. */
NSString *dataReturned = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
alertWithOkButton = [[UIAlertView alloc] initWithTitle:@"Status..." message:@"%@",dataReturned cancelButtonTitle:@"Okay", nil];
[alertWithOkButton show];
[alertWithOkButton release];
}
-(IBAction)dismissKeyboard: (id)sender {
[sender resignFirstResponder];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
l'en-tête/.h fichier:
#import <UIKit/UIKit.h>
@interface AuthViewController : UIViewController {
IBOutlet UITextField *userName;
IBOutlet UITextField *password;
IBOutlet UIButton *loginbutton;
IBOutlet UIActivityIndicatorView *indicator;
UIAlertView *alertWithOkButton;
UIAlertView *alertWithYesNoButtons;
}
@property (nonatomic, retain) UITextField *userName;
@property (nonatomic, retain) UITextField *password;
@property (nonatomic, retain) UIButton *loginbutton;
@property (nonatomic, retain) UIActivityIndicatorView *indicator;
- (IBAction)dismissKeyboard: (id)sender;
- (IBAction) loginButton: (id) sender;
@end
Quelle est la Message d'erreur? Où se bloque-t-il? Votre alertWithOkButton est-il déclaré en tant que variable? Sinon, vous devez changer cette ligne de code pour UIAlertView * alertWithOkButton = ... – Rog
Le simulateur fonctionne bien mais dès que je clique sur le bouton de connexion, la barre d'état affiche 'Signal reçu du programme GDB:' SIGABRT '. –
@Aniruddh Oui, cette erreur semble correspondre au problème décrit dans ma réponse. –