0

私は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;
}
4

2 に答える 2

1

あなたはこれを行うことができます :

if ([loginStatus isEqualToString:@"Welcome to my site..."]) {
    // Show welcome view controller
    NextViewController *nextViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"myNextView"];
    [self.navigationController pushViewController:nextViewController animated:YES];
} else {
    greeting.text = @"Login was not correct";
}

ここで、@"myNextView"はNextView識別子です。

于 2012-12-26T07:53:26.507 に答える
0

結果を確認できます

if ([loginStatus isEqualToString:@"Welcome to my site..."]) {
    // Show welcome view controller
} else {
    greeting.text = @"Login was not correct";
}

PHPを介してより役立つ文字列を返すこともお勧めします


アップデート

新しいビューを表示するためのチュートリアルはたくさんあります。

これをここでチェックしてください:CocoaTouchでプログラム的にビューを切り替える

于 2012-12-25T14:48:37.520 に答える