0

是否可以从 推送到新的视图控制器ConnectionDidFinishLoading

我有以下内容,它执行ConnectionDidFinishLoading但不推送到新的视图控制器。

-(void)connectionWithURLString:(NSMutableArray *)urlString
{
    NSDate *now =  [NSDate date];
    int userID = [[clientDataStruct.clientData objectForKey:@"number"] intValue];
    NSDate *date = self.datePicker.date;
  // NSLog(@"obj: %@", urlString);

    NSString *extrString = [NSString stringWithFormat:@", customerdetails:{customer_id = %d, job_date = %@, date_created = %@}",userID,date, now];

    NSString *post = [NSString stringWithFormat:@"json=quote:{%@%@}", urlString, extrString ];

     NSLog(@"post: %@", post);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *value = [defaults objectForKey:@"value"];

    NSString *jsonUrl = [NSString stringWithFormat:@"xxx?task=add_quote&user_id=%@&customer_id=%@",value, [clientDataStruct.clientData valueForKey:@"number"]];

    [request setURL:[NSURL URLWithString:jsonUrl]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:postData];

    NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];



    if (!connection)
        NSLog(@"Connection failed!");
}

- (void)Success
{

        UIStoryboard *subVc = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
        UserTableView *userTable = [subVc instantiateViewControllerWithIdentifier:@"UserTableView"];

        userTable.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self.navigationController pushViewController:userTable animated:YES];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

}


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"%@", error);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [self performSelectorOnMainThread:@selector(Success) withObject:Nil waitUntilDone:YES];
    NSLog(@"connectionDidFinishLoading%@", connection);
}

一切正常,并返回我的数据和数据被添加到SQL. 我的NSLog表明ConnectionDidFinishLoading。但它不会推送到新的 View Controller。

感谢您的帮助,正在为此挠头。

感谢 Fahim 的建议允许我进一步调试,导航视图与返回的模型控制器中断。将其更改为推送,一切正常

4

2 回答 2

1

第 1 点

这不适用于您,因为您没有导航控制器。确保您有导航控制器。

第 2 点

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [self performSelectorOnMainThread:@selector(LoginSuccess) withObject:Nil waitUntilDone:YES];
    NSLog(@"connectionDidFinishLoading%@", connection);
}

这是不对的。即使用户输入了错误的用户名或密码,您仍然允许用户登录。

检查您在 connectionDidFinishLoading 中获得的响应,然后根据此响应进行转换。

例如,如果您在后端有 PHP,您的代码将是

sql query here to add data

if (data added) {
    echo "valid";
} else {
    echo "invalid";
}

现在在 connectionDidFinishLoading 中检查此响应,并基于此进行转换

于 2013-08-21T07:03:11.453 回答
0

首先检查您的 LoginSuccess 是否被调用,如果是,则粘贴此

UserTableView * userTable =[self.storyboard instantiateViewControllerWithIdentifier:@"UserTableView"];
[self.navigationController pushViewController:userTable animated:YES]

像这样故事板编号但是用 UserTableView 替换 ResultsTableView

于 2013-08-21T06:55:33.870 回答