我的视图控制器StartViewController由另外两个视图控制器(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;帧= ( 0;748 1024);转换= 0,1,-1,0,0,0;自动调整大小= RM+BM;层=>
它的引用是我所需要的(0x81d6710),但它的类是一个UIViewController,而不是我的自定义视图控制器。
发布于 2013-02-04 15:55:20
最后,我设置了一个属性,它不回答原来的问题(对不起)。不过,确实应该有一种方法,即使我是通过评估超级视图的框架来做到的。
发布于 2013-01-31 17:27:28
而不是
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]) );发布于 2013-01-31 17:30:05
如果搜索视图的控制器,可能需要这样做:[self.view.superview nextResponder];
https://stackoverflow.com/questions/14631273
复制相似问题