用一个分类,具体: 
.h


#import <UIKit/UIKit.h> @interface UIView (CurrentController) /** 获取当前View的控制器对象 */
-(UIViewController *)getCurrentViewController; @end

.m

#import "UIView+CurrentController.h"

@implementation UIView (CurrentController)

/** 获取当前View的控制器对象 */
-(UIViewController *)getCurrentViewController{
UIResponder *next = [self nextResponder];
do {
if ([next isKindOfClass:[UIViewController class]]) {
return (UIViewController *)next;
}
next = [next nextResponder];
} while (next != nil);
return nil;
} @end 应用 : 在cell中拿到 控制器 然后 可以直接在 cell中 将 下一个控制器 直接 push。 这个的巧妙利用可以很方便的对view进行封装。

 

 
 
 

iOS-获取当前View所在的控制器的更多相关文章

  1. iOS获取窗口当前显示的控制器

    解决类似网易新闻客户端收到新闻推送后,弹出一个UIAlert,然后跳转到新闻详情页面这种需求 1.提供一个UIView的分类方法,这个方法通过响应者链条获取view所在的控制器 - (UIViewCo ...

  2. iOS 获取键盘view 覆盖新view

    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];    UIView * keyview=[[w ...

  3. IOS 获取当前对象所在的VC

    id next = [self nextResponder] ; while (next != nil) { next = [next nextResponder]; if ([next isKind ...

  4. 获得view所在的控制器

    - (UIViewController*)getViewController{ for (UIView* next = [self superview]; next; next = next.supe ...

  5. IOS第12天(1,UIViewController控制器的创建的 三种方式,和第一个view创建)

    *************HMAppDelegate.m中 @implementation HMAppDelegate - (BOOL)application:(UIApplication *)app ...

  6. iOS Programming View Controllers 视图控制器

    iOS Programming View Controllers  视图控制器  1.1  A view controller is an instance of a subclass of UIVi ...

  7. iOS 自定义view里实现控制器的跳转

    1.view里实现控制器的modal 拿到主窗口的根控制器,用根控制器进行modal需要的modal的控制器 场景:点击自定义view里的按钮实现控制器的modal UIViewController ...

  8. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  9. 【iOS开发-21】UINavigationController导航控制器初始化,导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最以下,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

随机推荐

  1. [Algorithm] Longest Substring Without Repeating Characters?

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  2. [Git] Change the commit message of my last commit

    Did you make a typo in your last commit message? No problem, we can use the git --amend command to c ...

  3. 【nodejs】理想论坛帖子下载爬虫1.07 使用request模块后稳定多了

    在1.06版本时,访问网页采用的时http.request,但调用次数多以后就问题来了. 寻找别的方案时看到了https://cnodejs.org/topic/53142ef833dbcb076d0 ...

  4. .NET 托管、非托管、本地:这些代码有什么区别?

    http://www.codeguru.com/Csharp/.NET/cpp_managed/article.php/c4871 本文内容 什么是托管代码? 什么是非托管代码? 什么是本地代码? 托 ...

  5. 牛客网-《剑指offer》-调整数组顺序使奇数位于偶数前面

    题目:http://www.nowcoder.com/practice/beb5aa231adc45b2a5dcc5b62c93f593 C++ class Solution { public: vo ...

  6. Linux中使用sed命令或awk命令修改常规配置文件

    一.方案: Linux中使用sed命令或awk命令修改常规配置文件 二.步骤: 1.假设有一个a.txt,内容如下: #!/bin/bash aa= bbb= ccc= #ddd= 2.如果想要把里面 ...

  7. Go语言中Socket通信之Tcp客户端

    1.用法: (1)定义远程IP地址.使用net.ResolveTCPAddr()方法,定义一个TCP地址,做为目标连接地址. (2)调用net.DialTCP("tcp",nil, ...

  8. Jaspersoft Studio 导出PDF格式中文不显示

    1:设置字体 2:应用上面设置的字体

  9. 使用Gulp

    为什么要使用Gulp 在前端开发中通常须要做,预处理语言的编译.js文件的压缩.css文件的压缩.图片的压缩等一系列工作,而使用Gulp能够自己主动化的完毕这些工作,从而提高站点的开发效率,在我的博客 ...

  10. Maven的JAR包仓库,不用再百度搜JAR包了!

    http://search.maven.org/ 今天初学Maven,发现Maven的中央仓库里差点儿什么jar都有...........还有各种版本号... 你值得拥有!