快速获取 UIViewController 的类名 [英] Get class name of UIViewController in swift
本文介绍了快速获取 UIViewController 的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何快速获取UIViewController
类的类名
在 Objective C 中,我们可以这样做:
In Objective C, we can do something like this :
self.appDelegate = (shAppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *last_screen = self.appDelegate.popScreens.lastObject ;
if(last_screen.class != self.navigationController.visibleViewController.class){
//.......
}
但很快我就这样尝试了
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let last_screen = appDelegate.popScreens?.lastObject as UIViewController
不能这样做.
if last_screen.class != self.navigationController.visibleViewController.class{
//....
}
没有UIViewController
的类方法,即最后一屏
no class method of UIViewController
i.e last screen
推荐答案
要知道您的班级名称,您可以这样调用:
To know your class name you can call something like this:
var className = NSStringFromClass(yourClass.classForCoder)
这篇关于快速获取 UIViewController 的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文