我的屏幕不会移动button上的下一个屏幕点击在iOS?

我想将一个屏幕移动到下一个,然后代码,但它不会在button单击的下一个屏幕上移动。这个代码中的问题是什么。

我想将一个屏幕移动到下一个,然后代码,但它不会在button单击的下一个屏幕上移动。这个代码中的问题是什么。

smsDisplayViewController.h @interface smsDisplayViewController : UIViewController<UITextFieldDelegate> { UIButton *btncomment; } - (IBAction)btncomment:(id)sender; @property(strong,nonatomic)UIButton *btncomment; @end smsDisplayViewController.m @implementation smsDisplayViewController @synthesize smsdisplay,Id,btncomment; - (IBAction)btncomment:(id)sender { CommentScreenViewController *viewController = [[CommentScreenViewController alloc] initWithNibName:@"CommentScreenViewController" bundle:nil]; [self.navigationController pushViewController:viewController animated:YES]; NSLog(@"btn press"); } [btncomment addTarget:self action:@selector(btncomment:) forControlEvents:UIControlEventTouchUpInside]; 

我想将一个屏幕移动到下一个,并为它编写代码,但不能在button单击时在下一个屏幕上移动。 我想将一个屏幕移动到下一个,并为它编写代码,但不能在button单击时在下一个屏幕上移动。

如果你不想使用NavigationController,那么使用下面的代码

 - (IBAction)btncomment:(id)sender { CommentScreenViewController *nextViewController = [[CommentScreenViewController alloc] initWithNibName:@"CommentScreenViewController" bundle:nil]; [self presentViewController:nextViewController animated: YES completion: nil]; } 

我认为你的自我不是一个导航控制器,所以属性

 self.navigationController 

返回零!

如果你愿意,你可以在不使用导航控制器的情况下在控制器之间切换,或者使用故事板模式来显示新的控制器

 UIViewController *newViewController = [[UIViewController alloc] init]; [self presentViewController: newViewController animated: YES completion: nil];