在UIView类中调用presentModalViewController

时间:2011-04-26 00:22:28

标签: iphone objective-c cocoa-touch

我的类是UIView,我无法将其更改为UIViewController,因为它被另一个类中的loadNibNamed调用。

我知道presentModalViewController会向UIViewController发送消息,那么我在UIView类中如何解决这个问题呢?

这会导致崩溃,这是正常现象:

[self presentModalViewController .... 

尝试了这个,但被叫视图剂量被拉了:

.h
@class Setting;
@interface SettingProfile : UIView ...
Setting *setting;
@property (nonatomic, retain) Setting *setting;

.m
@synthesize setting;
...
[setting presentModalViewController .... 

我试过了 this thread ,但没有多大帮助。

1 个答案:

答案 0 :(得分:2)

你不能在UIView上使用presentModalViewController,这只是不起作用。你有几个选择:

  • 重构,因此您的设置内容位于UIViewController子类中。
  • 将您的Setting UIView子类添加为当前视图控制器视图的子视图。为视图设置动画,使其像presentModal动画一样弹出。

好像你并不热衷于第一个选项,所以要做第二个选项,你需要:

  • 将Setting UIView上的框架设置为屏幕外(底部)。
  • Start一个动画块。
  • 将设置视图添加为主视图控制器视图的子视图。
  • 将帧设置为屏幕(因此动画块会将视图从底部屏幕边缘下方向上移动到屏幕上)。
  • Commit动画块。