3

私は新しい iOS です。ストーリーボードを使用してリスト データ関数のデモを実装し、データを追加します。私の AddWrokLogViewController には、メソッド (IBAction)done:(id)sender bind + ボタンがあります。次のように、私のdo関数では、ユーザー入力をチェックし、ユーザー入力データをhttpポストで保存したいと考えています。リモート保存に成功したら、リストビューに戻りたい。

前と同じようにアップルの記事紹介のストーリーボードを検索しますが、このデモでは、ユーザーが追加ボタンをタップすると、リスト ページ ビューに直接転送されます。はじめに/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