我有我的按鈕在這裏,在這個功能的結尾,我想切換到另一個視圖控制器。然而,我無法弄清楚如何切換它,我只爲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;
}
}
任何幫助將不勝感激!
謝謝!
你試過控制從按鈕拖動到新的視圖控制器,並給它一個模態賽格?我假設你正在使用故事板。 –