ios - 找出superview的类名

标签 ios objective-c

我的 View Controller StartViewController 由其他两个 View Controller (RootViewController 或 TelnetAddressbookViewController)之一打开/添加(addSubview)。我试图找出这两个中的哪一个是启动 StartViewController 的那个。

NSLog(@"superview %@",self.view.superview.description);
NSLog(@"superview %@",self.superclass);

if ([self.view.superview isKindOfClass:[RootViewController class]]) {

    NSLog(@"launched by RootViewController");

}else if ([self.view.superview isKindOfClass:[TelnetAddressbookViewController class]]) {

    NSLog(@"launched TelnetAddressbookViewController");
}

[self.view removeFromSuperview];

第一个 NSLOG (self.view.superview.description) 输出:

superview UIView: 0x81d6710; frame = (0 0; 748 1024); transform = [0, 1, -1, 0, 0, 0]; autoresize = RM+BM; layer = >



它的引用是我需要的(0x81d6710),但它的类是 UIViewController 而不是我的自定义 View Controller 。

最佳答案

代替

NSLog(@"superview %@",self.view.superview.description);

你要...
#import <objc/runtime.h>
NSLog(@"superview %s",class_getName([self.view.superview class]) );
/* or if you want an NSString */
NSLog(@"superview %@", NSStringFromClass([self.view.superview class]) );

关于ios - 找出superview的类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14631273/

相关文章:

ios - SKScene 节点未检测到触摸

ios - Xcode 给出了注释文本 block 中特定单词的错误

objective-c - 混合 Swift 和 Objective C : using Swift types in Objective C

objective-c - 测量线程等待锁所花费的时间(由 coredata 锁定)

ios - 在 appdelegate 中以编程方式选择 tableview 单元格不起作用

ios - 为什么 AppDelegate 和台风的行为不同?

ios - 在不切换选项卡的情况下从另一个选项卡在选项卡栏 Controller 中显示 View Controller

iphone - iOS 6 调试控制台不见了?

ios - NSOperationQueue将在内存中保留多长时间?

ios - 代码签名突然停止工作