2016-09-30 5 views
-1

iOSアプリケーションには、異なる情報を表示する4つのタブがあります。ボタン操作で2つの異なるビューコントローラを押す - iOS

私の2番目のタブのviewControllerでは、私は1つのボタンをbutton1として指定します。これは、SignInViewController画面に移動し、3番目のタブ表示コントローラーはloginViewControllerです。

両方のViewControllersに登録するオプションがあります。すでに存在しているユーザーだけでなく、両方のViewControllersにログインすることができます。ここでSignInViewControllerには、registerButtonという名前のボタンがあります。今、このregisterButtonアクションでは、RegisterViewControllerをプッシュしています。また、LoginViewControllerのSignInViewControllerと同じものですが、ボタンにはregisterButton2という名前が付いています。今このregisterButton2アクションで私は同じRegisterViewControllerをプッシュしました。私は私がloginViewControllerから通じなくなっていた場合、私はShippingViewControllerをプッシュするとSaveButtonActionで、その後RegisterViewControllerするSignInViewControllerから通じなくなっていた場合、私はボタンを持っている今、私は正確にしたいことはRegisterViewControllerである。ここ

はSaveButtonActionにSaveButtonとして名前、それをすることができますRegisterViewController次にSaveButtonActionで `AccountViewController 'をプッシュします。 > SignInViewController - - > RegisterViewController - > ShippingViewController(2)tabbaritem3 - > loginViewControoler - > RegisterViewController - ショート(1)tabbaritem2で

IはSaveButtonActionで次のコードを試みた> AccountViewController

しかしその動作しません。事前に

- (IBAction)SaveButtonAction:(id)sender{ 


    if(_tabBarController.tabBarItem.tag == 2){ 

     UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
     ShippingViewController *shipVc = [story instantiateViewControllerWithIdentifier:@"ShippingViewController"]; 
     [self.navigationController pushViewController:shipVc animated:YES]; 

    else if(_tabBarController.tabBarItem.tag == 3){ 

     UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
     AccountViewController *acntVC = [story instantiateViewControllerWithIdentifier:@"AccountViewController"]; 
     [self.navigationController pushViewController:acntVC animated:YES]; 

    } 

} 

親切help.Thanks:

は、ここに私のコードです。

+0

私は本当にあなたの説明の意味をなすが、何私が手にすることはあなたには、いくつかの条件に基づいて、一つのボタンから別のセグエを実行したいということであることはできません。この場合、ビューコントローラオブジェクトから目的のシーンにセグを作成し、識別子を付けます。あなたの 'saveButtonActin'メソッドでは' self.performSegueWithIdentifier'を使うことができます。どのセグ識別子が適切かを指定してください – Paulw11

+0

あなたは3〜4回はあなたの質問を読んでもわかりませんが、私は理解できません... –

+0

@hani私はちょうどあなたの質問を編集し、それを承認し、質問自体と混乱しないでください。 – vaibhav

答えて

0

//このコードは、LoginVCからRegisterVCにプッシュすると発生します。他の場合に似ていますが、@ "login"の代わりに@ "signin"を割り当てます。

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
RegisterViewController *registerVc = [story instantiateViewControllerWithIdentifier:@"RegisterViewController"]; 
registerVc.imFromLogin = @"login"; 
[self.navigationController pushViewController:registerVc animated:YES]; 
- (IBAction)SaveButtonAction:(id)sender{ 
    if([_imFromLogin isEqualToString:@"login"]) 
    { 
     [self performSegueWithIdentifier:@"regToAccount" sender:nil]; 
    }else if ([_imFromLogin isEqualToString:@"signin"]) { 
     [self performSegueWithIdentifier:@"registerToShipping" sender:nil]; 
    } 
} 
0

LoginVCから押しながらわずかRegisterViewControllershouldFromLoginを言うことができます)でbooleanを使用して、truebooleanとして設定し、他の場合にfalseとして渡します。次に、ボタン操作でbooleanをチェックし、それに応じて異なるVCにナビゲートします。

デモコード:

//This code when you push to RegisterVC from LoginVC. Similar thing for other case with shouldFromLogin as NO. 

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
RegisterViewController *registerVc = [story instantiateViewControllerWithIdentifier:@"RegisterViewController"]; 
registerVc.shouldFromLogin=YES; 
[self.navigationController pushViewController:shipVc animated:YES]; 

すると以下のように列挙型を宣言し、あなたのRegisterViewController.hファイルで

- (IBAction)SaveButtonAction:(id)sender{ 
if(shouldFromLogin){ 
    //Pass to AccountViewController 
} 
else{ 
    //Pass to ShippingViewController 
} 
} 
0

を確認してください。新しいを宣言し、

typedef NS_ENUM(NSUInteger, RegisterViewControllerAction) { 
    RegisterViewControllerActionShipping, 
    RegisterViewControllerActionAccount, 
} 

をもRegisterViewControllerクラスのコンストラクタ:

@interface RegisterViewController 

@property (readonly) RegisterViewControllerAction action; 
- (id)initWithAction:(RegisterViewControllerAction)action; 

@end 

@implementation RegisterViewController 
@synthesize action = _action; 

- (id)initWithAction:(RegisterViewControllerAction)action { 
    if (self = [super initWithNib:xxx]) { 
     _action = action; 
    } 
} 

- (IBAction)SaveButtonAction:(id)sender { 
    if (_action == RegisterViewControllerActionShipping) { 
     .... 
    } else if (_action == RegisterViewControllerActionAccount) { 
     .... 
    } 
} 
+0

ここにコードを追加してください。ありがとうございます。 !! – hani

+0

@hani私の編集を参照してください。 –

+0

ありがとうございました。新しい開発者です。あなたは私のプロジェクトで何を書きますか? – hani

0

これは、選択したタブバーインデックスを使用して行うことができます。

if(theTabBar.selectedItem == 2){ 
    ShippingViewController *shipVc = [story instantiateViewControllerWithIdentifier:@"ShippingViewController"]; 
    [self.navigationController pushViewController:shipVc animated:YES]; 
} 

else if(theTabBar.selectedItem == 3){ 
    AccountViewController *acntVC = [story instantiateViewControllerWithIdentifier:@"AccountViewController"]; 
    [self.navigationController pushViewController:acntVC animated:YES]; 
} 
+0

私は既に動作していないことを試しました – hani

+0

またこのコードをチェックしてください:tabBarController.selectedIndex == 2。 – KKRocks

関連する問題