如何从一个视图导航到另一视图

发布于 2024-11-14 07:56:51 字数 615 浏览 2 评论 0原文

我使用按钮操作来弹出子视图,如下代码;

- (IBAction)pickerUpBtn:(id)sender {

    PickerPopUpController *screen = [[PickerPopUpController alloc]initWithNibName:@"PickerPopUpController" bundle:Nil];
    [self.view addSubview:screen.view];
    [self presentModalViewController:screen animated:YES];
}

在我需要去上一个窗口之后;所以我使用了另一个按钮操作,并在操作中添加了以下代码

PickerViewController *screen = [[PickerViewController alloc]initWithNibName:@"PickerViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:screen animated:YES];

,但它不会导航到上一个视图。我怎么能做到呢?

I used button action to to pop sub view sing below code;

- (IBAction)pickerUpBtn:(id)sender {

    PickerPopUpController *screen = [[PickerPopUpController alloc]initWithNibName:@"PickerPopUpController" bundle:Nil];
    [self.view addSubview:screen.view];
    [self presentModalViewController:screen animated:YES];
}

after i need to go previous window; So i used another button action for it and add bellow code inside action

PickerViewController *screen = [[PickerViewController alloc]initWithNibName:@"PickerViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:screen animated:YES];

But It does not navigate to previous view . How could i do it ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你怎么敢 2024-11-21 07:56:51

回去,

[self dismissModalViewControllerAnimated:YES]

to go back,
do

[self dismissModalViewControllerAnimated:YES]
淡水深流 2024-11-21 07:56:51

您只需将单个代码放入按钮操作中。无需创建parentViewController 对象。

IE,

-(IBAction)btnaction:(id)sender{

[self dismissModalViewControllerAnimated:YES];

}

You need to put only that single code in the Button action..No need of making object of parentViewController.

ie,

-(IBAction)btnaction:(id)sender{

[self dismissModalViewControllerAnimated:YES];

}
倾听心声的旋律 2024-11-21 07:56:51

您需要为您的 ViewController 添加 canceldone ,以返回到父视图控制器。

实现Cancel按钮后,您必须使用dismissModalViewControllerAnimatedCancel按钮的action函数中关闭视图控制器功能

[self dismissModalViewControllerAnimated:YES];

You need to add cancel and done for your ViewController which is present modely to come back to parent view Controller.

After implementing the Cancel button, you have to dismiss your viewcontroller in the action function of Cancel button using the dismissModalViewControllerAnimated function

[self dismissModalViewControllerAnimated:YES];
唠甜嗑 2024-11-21 07:56:51

对于推送视图控制器,您可以执行如下操作,

 PickerViewController *screen = [[PickerViewController alloc]initWithNibName:@"PickerViewController" bundle:[NSBundle mainBundle]];

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

然后要返回,您必须在“屏幕”视图控制器中添加一个按钮,并且您必须编写以下代码的单击事件,

 [self.navigationController popViewControllerAnimated:YES];

希望这会有所帮助。

如有任何困难请告诉我。


如果您使用的是“presentmodelviewcontroller”方法,那么您必须在按钮单击中写下一行。

 [self dismissModalViewControllerAnimated:YES];

For push view controller, you can do like below,

 PickerViewController *screen = [[PickerViewController alloc]initWithNibName:@"PickerViewController" bundle:[NSBundle mainBundle]];

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

Then for go back, you have to add one button in "Screen" view controller and it's click event you have to write below code,

 [self.navigationController popViewControllerAnimated:YES];

Hope, it would be helpful.

Let me know in case of any difficulty.


If you are using the method "presentmodelviewcontroller" then you have to write below line in button click.

 [self dismissModalViewControllerAnimated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文