简体   繁体   English

Objective-C以编程方式在另一个视图控制器上显示一个视图控制器

[英]Objective-C Showing a view controller on another view controller programmatically

I've got one problem. 我有一个问题。 I have a viewController1 in which I click a button. 我有一个viewController1,在其中单击一个按钮。 When I hit this button, I want it to show another view controller (viewController2) on viewController1 (viewController2 is a little transparent). 当我按下此按钮时,我希望它在viewController1上显示另一个视图控制器(viewController2)(viewController2有点透明)。 I'd like to do this programmatically. 我想以编程方式执行此操作。 I tried this but when I hit the button nothing happens: 我尝试了这个,但是当我按下按钮时什么也没发生:

Notification *newView = [[Notification alloc]initWithNibName:@"Notification" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];

I renamed some variables to make it clearer. 我重命名了一些变量以使其更清晰。 Thanks for answers! 感谢您的回答!

EDIT: Maybe I wasn't clear enough, I want viewController2 to be ONTOP of viewController1 编辑:也许我还不够清楚,我希望viewController2是viewController1的ONTOP

Try below:- 请尝试以下:

 Notification *newView = [[Notification alloc]initWithNibName:@"Notification" bundle:nil];
  [self presentViewController:newView  animated:YES completion:nil];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一个视图控制器中控制对象? (Xcode:objective-c) - How to control objects in another view controller? (Xcode:objective-c) Objective-C中的详细视图控制器 - Detailed view controller in Objective-C (Objective-C)打开视图控制器 - (Objective-C) Open view controller Objective-C当前视图控制器及其导航控制器 - Objective-C Present View Controller with its Navigation Controller 将变量传递给Objective-C中嵌入在导航控制器中的View Controller - Pass variable to View Controller Embedded in Navigation Controller in Objective-C 在使用导航控制器?[Objective-C]的情况下将视图控制器初始化为初始视图控制器 - Initializing a view controller as a initial view controller while using navigational controller ?[Objective-C] 当我尝试从另一个视图控制器(Objective-c?)访问变量时,为什么变量为null? - Why is my variable null when I am attempting to access it from another view controller (Objective-c? 使用Objective-C类别时如何导入另一个视图控制器头文件? - How to import another view controller header file when I use Objective-C category? 当我尝试在另一个视图控制器中访问数据时,为什么它为null? (Objective-C,XCode) - Why is it null when I try to access data in another view controller? (Objective-C, XCode) 当在objective-c中点击pin图时移动到另一个视图控制器 - Move to another view controller when the pin map tapped in objective-c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM