xcode でシングル ビュー アプリケーション テンプレートを使用しています。最初のビュー コントローラーを作成し、新しい .m と .h と xib を使用して別のビュー コントローラーを追加しました。
ボタン IBAction をクリックして 2 番目のビューに移動できますが、「戻る」ボタンに使用しているコードでは最初のビューに戻らず、すべてがクラッシュします。私が使用していたチュートリアルに従っていると思われるコードを含めました。さらに、ボタンをクリックして制御し、.h の IBAction に行をドラッグして、secondViewController ボタンにフックしました。これは、最初のビュー コントローラーで行ったことであり、そこで動作するようです。
誰かがそれを助けることができれば、それは素晴らしいことです!
//from my first view controller .h which works
-(IBAction) buttonPressedPayTable: (id) sender;
//from my first view controller.m which also works and gets me to the second view
-(IBAction) buttonPressedPayTable: (id) sender
{
SecondViewController *payTableView = [[SecondViewController alloc]
initWithNibName:@"SecondViewController" bundle:nil];
[self.view addSubview:payTableView.view];
}
//from my second view controller .h that will not get me back to the first view without crashing
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
}
-(IBAction) back: (id)sender;
@end
//from my second view controller .m which doesn't seem to work
#import "SecondViewController.h"
@implementation SecondViewController
-(IBAction) back: (id)sender
{
[self.view removeFromSuperview];
}
@end