2012-06-22 40 views
-5

我是iPhone開發的新手。我將學會創建一個用戶需要登錄的頁面。如果用戶憑證是正確的,那麼他/她應該被允許進入應用程序中的下一頁。iPhone用戶登錄的編碼示例

任何幫助將不勝感激。

在此先感謝。在你的登錄按鈕

+0

我相信你應該提供更多的細節,如果你希望得到答案。您的要求太寬。 –

+0

只是試一下,問你的疑惑。 –

+2

[你有什麼試過](http://www.whathaveyoutried.com) – akk

回答

1

下面提供的方法...

-(IBAction)onClickLogin:(id)sender 
{ 
    if ([txtUserName.text isEqualToString:@""]) 
    { 
     ///here paste your Alert View with message:@"Please Fill Up Email and Password" 
    } 
    else if([txtPassWord.text isEqualToString:@""]) 
    { 
     ///here paste your Alert View with Message message:@"Please Fill Up Email and Password"   
    } 
    ///if here you use web-service for store the user data then give the request with username and password also 
    if([txtUserName.text isEqualToString:storeduserName] && [txtPassWord.text isEqualToString:storedpassWord] 
    { 
     yourViewController *objviewController = [[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil]; 
     [self.navigationController objviewController animated:YES]; 
    } 
    else 
    { 
     ///Alert with username or password is incorrect try again 
    } 
} 

還檢查下面演示...

https://github.com/ijoshsmith/iOSLogin

希望這有助於你... :)

+0

我認爲在這裏你沒有檢查天氣給出的憑據正確或錯誤 –

+0

不,我給存儲的用戶名在哪裏人給出正確的用戶名,與給出的用戶名,所以如果兩個都是正確的,那麼用戶可以在另一個不允許推下一個視圖.. –

+0

好吧,那麼我們可以通過只有一個用戶cm登錄對不對? –

3

我們在這裏調用執行選擇器sentAuthenticateDetails進行Web服務身份驗證。

-(IBAction)login_Button_Clicked:(id)sender 
{ 

    [currentTextField resignFirstResponder]; 
    BOOL allFieldsSuccess; 

    if((![self.userNameOrEmail_Str length]>0)||(![self.password_Str length]>0)) 
    { 
     UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"for Login" message:@"Please enter proper Userid & Password" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alertView show]; 
     [alertView release]; 
     NSLog(@"no values"); 
     allFieldsSuccess = NO; 
     return; 

    } 
    else 
    { 
     allFieldsSuccess = YES; 
    } 

    if (allFieldsSuccess==YES)// && (emailSuccess==YES)) 
    { 

     [self.spinner startAnimating]; 

     [self performSelector:@selector(sentAuthenticateDetails) withObject:nil afterDelay:0.2]; 
    } 
}