私はiPhoneアプリケーションの初心者です。このチュートリアルに従って、iPhoneからログインしました。
私は以下のようなphpファイルを持っています。
index.php
<?php
$user = $_POST['uname'];
if ($user == 'user') {
echo "Welcome to my site...";
} else {
echo "Invalid User";
}
?>
アプリケーションを実行し、ユーザーとしてユーザー名を入力し、テキストとしてパスワードを入力すると、Welcome tomysite...として出力されます。
ウェルカムメッセージの代わりに、ウェルカム画面、つまりストーリーボードにあるViewControllerに移動します。これを行う方法はありますか?
完全なコードは以下のとおりです。
-(IBAction)buttonClick:(id)sender
{
greeting.text= @"";
NSString* username = nameInput.text;
NSString* pass = passInput.text;
greeting.hidden = NO;
if([nameInput.text isEqualToString:@"" ] && [passInput.text isEqualToString:@""])
{
greeting.text = @"Please enter username and password.";
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
return;
}
if([nameInput.text isEqualToString:@"" ])
{
greeting.text = @"Please enter username.";
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
return;
}
if([passInput.text isEqualToString:@""])
{
greeting.text = @"Please enter password.";
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
return;
}
NSString *post = [[NSString alloc] initWithFormat:@"uname=%@&pwd=%@",username,pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://localhost:8888/PhPTesting/index.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
indicator.hidden = NO;
webData = [[NSMutableData data] retain];
}
else
{
}
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
nameInput.text = nil;
passInput.text = nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
greeting.text = loginStatus;
[loginStatus release];
[connection release];
[webData release];
indicator.hidden = YES;
}