3

我是新ios,我使用storyboard实现列表数据功能demo,包括添加数据。在我的 AddWrokLogViewController 中,我有一个方法 (IBAction)done:(id)sender 绑定 + 按钮。如下,在我的 do 函数中,我想检查用户输入并通过 http post 保存用户输入数据。当远程保存成功发布数据时,我想返回列表视图。

和之前我搜索苹果文章介绍故事板一样,但在这个演示中,当用户点击添加按钮时,直接转移到列表页面视图:http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/简介/Introduction.html#//apple_ref/doc/uid/TP40011318-CH1-SW1

如果我使用 AFHTTPClient 在远程服务器成功保存数据,则返回列表页面视图,或仍在添加页面视图并显示错误消息。

谁能给我一些建议,谢谢!

NSString *url = [NSString stringWithFormat:@"%@",api_createworklog];
NSDictionary *params=[NSDictionary dictionaryWithObjectsAndKeys:uname,@"loginname",token,@"token",beginTime
                      ,@"beginTime",content,@"content",address,@"address",projectNameTemp,@"projectName"
                      ,workType,@"workType",workDate,@"workDate",validDate,@"validDate", nil];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:BASE_URL]];
[client postPath:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSString *responseString = [operation responseString];
    NSDictionary *data = [responseString objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    NSString *sysCode = [data objectForKey:@"syscode"];
    NSString *businessCode = [data objectForKey:@"businesscode"];
    if(sysCode != nil && ![sysCode isEqualToString:@""] && businessCode != nil && ![businessCode isEqualToString:@""]){
        if([sysCode isEqualToString:ws_access_success] && [businessCode isEqualToString:ws_access_success]){
            //[self.navigationController popViewControllerAnimated:YES];
            addSuccess = true;
        } else{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"添加失败"                                                            message:responseString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alertView show];
        }
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSString *responseString = operation.responseString;
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"访问服务器异常,添加失败!"                                                            message:responseString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alertView show];
}];
4

0 回答 0