objective-c - 如何访问呈现模态视图的 UIViewController 类/类名?

标签 objective-c ios ipad uiviewcontroller

一个简单的问题

目前我呈现这样的模态视图:

+ (void)showModalController:(id)ContentController InViewController:(UIViewController*)vc withFrame:(CGRect)rect{

UINavigationController *modalViewNavController = [[UINavigationController alloc] initWithRootViewController:ContentController];
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;

[vc presentModalViewController:modalViewNavController animated:YES];

//it's important to do this after presentModalViewController
modalViewNavController.view.superview.frame = rect;

//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc.
modalViewNavController.view.superview.center = vc.view.center;

[modalViewNavController release];

}

我传递了将以自定义模式大小呈现的 UIViewController 内容的值。我还将 UIViewController 的值传递给将呈现模式的位置。

就代码而言,我想知道内容类中的“vc”名称(如果可以的话)。

编辑

假设我有 2 个类,其中一个称为 DetailViewController,其中将呈现模式。另一个称为ModalContentViewController

我想知道 ModalContentViewController 类(当 View 出现或加载时)DetailViewController 的名称。

有什么想法吗?

PD:当前使用...

XCode 4.4.1 iPad模拟器iOS5.1 iOS5.1

最佳答案

查找UIViewController属性presentingViewController。以下是文档中的引用:

If the view controller that received this message is presented by another view controller, this property holds the view controller that is presenting it. If the view controller is not presented, but one of its ancestors is being presented, this property holds the view controller presenting the nearest ancestor. If neither the view controller nor any of its ancestors are being presented, this property holds nil.

因此您可以使用该属性来获取当前 VC 的名称。

关于objective-c - 如何访问呈现模态视图的 UIViewController 类/类名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14167092/

相关文章:

iphone - NSURLConnection 异步间歇性地返回 null

ios - 与应用程序中只有 1 个屏幕的横向模式相关的问题

ios - 给定一个网页 url,我如何获取它的内容数据以生成链接预览,就像在 Facebook 和 Slack 中一样?

iphone - <错误> : CGContextSaveGState: invalid context 0x0 Error

iphone - 将pdf文件转换为文本文件

ios - 如何计算iOS中应用程序在后台花费的时间

ios - UINavigationController pushViewController 在中途暂停/卡住

ios - 将 UILabel 从一个 View 拖放到另一个 View - iOS

iphone - 在 View Controller 中为 iPhone/iPad 动态加载 Nib

objective-c - UISwitch 有时不发送 UIControlEvents