从 UIView ios 推送视图控制器 [英] push a view controller from a UIView ios

查看:21
本文介绍了从 UIView ios 推送视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于导航的应用程序.单击第一个屏幕中导航栏上的按钮,我可以按如下方式推送另一个视图控制器:

I have a navigation based application.On click of a button on the navigation bar in the first screen , I am able to push another view controller as follows :

 -(void) buttonClicked:(id)sender
{

    UIViewController*  mv = [[SecondViewController alloc] init];

    [[self navigationController] pushViewController:mv animated:YES];  

}

现在我有一个 UIView(单独的 .h 和 .m 文件)作为第一个屏幕的一部分.单击 UIView 中的按钮,我想推送 SecondViewController.我尝试了以下方法:

Now i have a UIView(separate .h and .m files) as part of the first screen. On click of a button in the UIView, i want to push the SecondViewController. I have tried the following :

 UIViewController*  mv = [[SecondViewController alloc] init];
 UIViewController * home=[[FirstViewController alloc]init];
 [[home navigationController] pushViewController:mv animated:YES];

它不起作用!!请帮忙

推荐答案

你可以使用这个.它对我来说非常有效:-

You Can use this. It Works very well for me:-

首先在 UIView 类中创建 AppDelegate 对象并初始化.然后在 Appdelegate.h 中创建 Navigationcontroller 对象:-

Firstly Create Object of AppDelegate in UIView Class and initialize it. Then create Navigationcontroller object in Appdelegate.h :-

@property(strong,nonatomic) UINavigationController *navControl;

在你的 UIView 类中实现你想要推送的代码:-

In your UIView Class implement this code where you want to push :-

ViewController *objview = [[ViewController alloc]init]; [appDelegate.navControl pushViewController:objview animated:YES];

这篇关于从 UIView ios 推送视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆