0

4つのviewcontrollerとその.h、.mファイルを含むアプリを作成しました...最初のviewcontrollerでボタンを押すとsecondviewcontrollerに移動し、2番目のviewcontrollerでは2つのボタンがあり、firstviewcontrollerと別のボタンに戻るために使用されますこれはfirstviewcontroller.mの私のコードです

[[NSBundle mainBundle] loadNibNamed:@"SecondViewController" owner:self options:nil];

そして私のsecondviewcontrollerで最初のボタン

[[NSBundle mainBundle] loadNibNamed:@"FirstViewController" owner:self options:nil];

と別のボタン

[[NSBundle mainBundle] loadNibNamed:@"ThirdViewController" owner:self options:nil];

firstviewcontrollerでボタンを選択すると、secondviewcontrollerが読み込まれますが、second view controllerでボタンを選択すると、Sigabartの警告が表示されます...

誰もがこれについて考えることができます...私はとても多くの方法を試しました..

4

4 に答える 4

4

次のアプローチを使用して、これらのタスクを実行できます。

アプローチ1:

FirstViewController.mで、ボタンクリックでこのコードを記述します。

SecondViewController *secondVC = [[SecondViewController alloc]initwithNibName:@"SecondViewController" bundle:nil];
[self.view addSubView:secondVC.view];

これにより、secondviewcontrollerが現在のビューに追加されます

SecondViewController.mで、3番目のビューを追加して次のように記述できます。

ThirdViewController *thirdVC = [[ThirdViewController alloc]initwithNibName:@"ThirdViewController" bundle:nil];
[self.view addSubView:thirdVC.view];

2番目のビューを削除するには、次のように記述します。

[self.view removeFromSuperview];

アプローチ2:

ナビゲーションコントローラーを使用します。

于 2012-06-15T05:30:28.907 に答える
2

このようなコードを使用する

FirstViewController *FVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

//For Push    
[self.navigationController pushViewController:FVC animated:YES];

//For Pop
[self.navigationController popViewControllerAnimated:YES];

:)

于 2012-06-15T05:33:41.807 に答える
1

iPhoneアプリのプログラミングでは、viewControllerは通常、ViewControllerを新しい別のViewControllerにプッシュするときに、1つずつスタックに格納されます。これらのコントローラーを同じ逆形式で削除します。したがって、新しいView Controllerをプッシュする場合は、次を使用します。

SecondViewController * second = [[SecondViewController alloc] initWithNibName:@ "SecondViewController" bundle:nil];

[self.navigationController pushViewController:second animated:YES];

現在のViewControllerを削除する場合は、次を使用してください。

`[self.navigationController popViewControllerAnimated:YES];

ビューコントローラのいずれかから最初のビューコントローラにジャンプしたい場合

[self.navigationController popToRootViewControllerAnimated:YES];

このコード行で、このスタックに表示されるビューコントローラーを取得できます

NSArray * viewArr = [self.navigationController viewControllers];

NSLog(@ "%@"、viewArr);

[self.navigationController popToViewController:[viewArr objectAtIndex:1]アニメーション:YES];

`

于 2012-06-15T05:34:29.167 に答える
1
//For going in forword direction you can use this block
{
FirstViewController *firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self.navigationController pushViewController:firstVC animated:YES];
[firstVC relese];
}

//For returning back you can use this block
{ 
   [self.navigationController popViewControllerAnimated:YES];
}


//But before using this line of code you have to alloc and make the property of    navigationController in your appDelegate

これがお役に立てば幸いです

于 2012-06-15T06:48:43.400 に答える