【发布时间】:2013-01-05 00:15:54
【问题描述】:
一个简单的问题
目前我呈现这样的模态视图:
+ (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 类(当视图出现或加载时)DetailViewController 的名称。
有什么想法吗?
PD:目前正在使用...
XCode 4.4.1 iPad模拟器iOS5.1 iOS5.1
【问题讨论】:
-
你能稍微整理一下你的问题吗?我很困惑您是获取内容控制器的名称还是呈现视图控制器的名称。此外,您应该考虑两个改进:将
ContentController声明为UIViewController *而不是id。这样可以确保如果您尝试传递不是UIViewController(子类)的内容,您将收到警告,这很好,因为initWithRootVC方法需要视图控制器。 -
其次,您可以考虑将此方法设置为
UIViewController上的类别,您可以通过转到文件> 新文件> obj-c 类别>UIViewController上的类别来实现。然后,将此方法作为实例方法添加到UIViewController。这是一种更自然的编写方法的方式,而不是从 (InViewController:) 传入视图控制器来呈现它 -
谢谢 MaxGabriel,我会做出改变并阅读一些关于类别的内容
标签: objective-c ios ipad uiviewcontroller