2013-07-27 114 views
-3

我有我的按鈕在這裏,在這個功能的結尾,我想切換到另一個視圖控制器。然而,我無法弄清楚如何切換它,我只爲iphone版本的應用程序工作。StoryBoard - 視圖控制器如何切換?

- (IBAction)loginMe:(UIButton *)sender { 
    [self.view endEditing:YES]; 
    NSURL *url = [NSURL URLWithString:@"http://192.168.1.111:8888/api.php"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
    [request setHTTPMethod:@"POST"]; 
    NSString *requester = [NSString stringWithFormat:@"type=account&username=%@&password=%@",self.username.text,self.password.text]; 
    NSData *requestBody = [requester dataUsingEncoding:NSUTF8StringEncoding]; 
    [request setHTTPBody:requestBody]; 
    NSURLResponse *response = NULL; 
    NSError *requestError = NULL; 
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError]; 
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    if([responseString isEqualToString:@"1"]) 
    { 
     self.data.text = @"Username or password incorrect"; 
    } 
    else 
    { 
     NSData* data = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 
     NSError *jsonParsingError = nil; 
     NSArray *publicTimeline = [NSJSONSerialization JSONObjectWithData:data 
                    options:0 error:&jsonParsingError]; 

     NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; 

     [ud setInteger:1 forKey:@"isLoggedin"]; 
     [ud setObject:[publicTimeline objectAtIndex:0] forKey:@"userid"]; 
     [ud setObject:[publicTimeline objectAtIndex:1] forKey:@"username"]; 
     [ud setObject:[publicTimeline objectAtIndex:2] forKey:@"loginstr"]; 
     [ud synchronize]; 
     [self animateLoginBox]; 
     self.data.text = responseString; 
    } 
} 

任何幫助將不勝感激!

謝謝!

+0

你試過控制從按鈕拖動到新的視圖控制器,並給它一個模態賽格?我假設你正在使用故事板。 –

回答

0

是您的視圖控制器嵌入導航控制器?如果是這樣;

將視圖控制器.h導入當前視圖控制器的頂部。 然後在故事板中爲該視圖控制器創建故事板ID。然後在其移動到新的視圖控制器的方法試試這個:

YourNewViewController *newVC = [self.storyboard instantiateViewControllerWithIdentifier:@"yourStoryboardID"]; 
[self.navigationController pushViewController:newVC animated:YES]; 

但如果它不嵌入導航控制器試試這個:

YourNewViewController *newVC = [[YourNewViewController alloc]init]; 
[self presentModalViewController:newVC animated:YES]; 

希望這有助於!

+0

不使用導航控制器。然而,presetnModalViewController說它已被棄用。任何其他想法? – Bioto

+0

試試,[self presentViewController:newVC animated:YES completion:nil]; – dylaank

+0

@NicholasYoung,如果您在文檔搜索中鍵入折舊方法的名稱,然後單擊該方法(通過它的紅線),它會告訴您替換方法是什麼。 – rdelmar

相關問題