1

我想知道如何启动 iPhone 登录页面。我曾尝试使用 SQL/PHP 并将其连接到 XCode,但没有成功。我想现在最好的办法是什么?

4

1 回答 1

0

抄袭教程

// LoginExampleViewController.h
#import <UIKit/UIKit.h>

@class LoginExampleViewController;

@interface LoginExampleAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    LoginExampleViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet LoginExampleViewController *viewController;

@end

// LoginExampleViewController.h

#import <UIKit/UIKit.h>

@interface LoginExampleViewController : UIViewController {

 IBOutlet UITextField *unameField;
 IBOutlet UITextField *passwordField;
 IBOutlet UIButton *loginButton; 
 NSMutableData *receiveData;

}

@property (nonatomic, retain) UITextField *unameField;
@property (nonatomic, retain) UITextField *passwordField;
@property (nonatomic, retain) UIButton *loginButton;
@property (nonatomic, retain) NSMutableData *receiveData;

-(IBAction)doLogin: (id)sender;


@end

// LoginExampleViewController.m
#import "LoginExampleViewController.h"

@implementation LoginExampleViewController


@synthesize unameField;
@synthesize passwordField;
@synthesize loginButton;
@synthesize receiveData;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

 [super viewDidLoad];

}

//Implement IBAction method
-(IBAction) doLogin: (id) sender
{


 NSString *uname= unameField.text;
 NSString *password= passwordField.text; 



 NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8888/powerplay/insert2.php?name=%@&password=%@",uname, password]]; //Here you place your URL Link

 NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
 NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];
 if (connection) {
  NSLog(@"connection successful");
 }
 else {
  NSLog(@"Failed");
 }
}


// Implement Connection delegate

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{

}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

 [receiveData setLength:0];
// NSURL *theURL=[response URL];
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
 NSLog(@"success",[receiveData length]);
 [connection release];
 [receiveData release];

} 


// Implement TextField delegate

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
 [textField resignFirstResponder];
 return YES;
}


// Implement TouchEvent


-(void)touchesBegan :(NSSet *)touches withEvent:(UIEvent *)event
{

 [super touchesBegan:touches withEvent:event]; 
} 

- (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 {
 [unameField release];
 [passwordField release];
    [super dealloc];
}




@end

为我工作,如果您有问题,请发表评论。

于 2013-05-09T21:43:47.763 回答