2016-11-10 5 views
0

私は両方の言語でアプリケーションをプログラミングしています:Android & iOSですが、私はAndroid上のIntentのように、ViewControllerから別のものにデータを移動するために同様のメソッドを使用する方法を見つけようとしています。 Android上で私のコードは次のとおりです。データを送信している活動でiOS用のAndroidのintent.putextraのようなメソッドはありますか?

public void goToUserScreen(UserModel userM) { 
     userModel = userM; 
     Intent intent = new Intent(HomeActivity.this, ProfileActivity.class); 
     intent.putExtra("USER_MODEL", userModel); 
     intent.putExtra("LOGIN_MODEL", loginModel); 
     intent.putExtra("NOTIFICATION_MODEL", notificationModel); 
     startActivity(intent); 
     finish(); 
    } 

受信している活動:

Intent intent = getIntent(); 
     loginModel =   (LoginModel) intent.getSerializableExtra("LOGIN_MODEL"); 
     notificationModel =  (NotificationModel) intent.getSerializableExtra("NOTIFICATION_MODEL"); 
     userModel =    (UserModel) intent.getSerializableExtra("USER_MODEL"); 

誰かがiOSの上でそれを行う方法を知っていますか?ちなみに、iOSの場合はXcode 8でプログラミングしていますので、誰かがSwift3でこれを解決するのに手伝ってもらえますか?

答えて

0

extrasは、ちょうどParcelable値のマップです。 iOSでは、NSDictionaryUIViewControllerに渡して、同様の効果で解析することができます。そのような:

ViewControllerBで次に
ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil]; 
viewControllerB.intentDictionary = [[NSDictionary alloc] init]; 
[self pushViewController:viewControllerB animated:YES]; 

LoginModel *loginModel = [intentDictionary objectForKey:"LOGIN_MODEL"]; 
NotificationModel *notificationModel = [intentDictionary objectForKey:"NOTIFICATION_MODEL"]; 
UserModel *userModel = [intentDictionary objectForKey:"USER_MODEL"]; 
+0

はそれが本当に私の問題を解決し、あなたの助けをありがとうございました。良い一日を! –

+0

ところで、あなたはSwift 3でこれを行う方法を知っていますか?私はSwift 3でこれに関する情報を得ていなかったので、Objective-Cでしか見つかりませんでした。助けてください! –

関連する問題