无法使用委托

时间:2012-11-08 07:47:13

标签: objective-c ios xcode cocoa-touch

我是目标c的新手,并试图掌握代表的方法和用法。目前我有Alertview类,我需要它来创建另一个类来调用它的功能。我设法用appdelegate类做同样的事情。但不能用我自己的班级来做。

                TableViewController *newControll = (TableViewController*)[UIApplication sharedApplication].delegate;
                [newControll openSettings];

这就是我试图访问我的方法的方式。 Compilator在newControll中看到了这个方法,但是调用它会得到unrecognizet选择器。

Basicaly我需要从另一个类调用之前已经创建过的函数。如果这是一个简单的解决方案,我很抱歉,但我还是不能很好地掌握代表和目标c。

也许不是每个人都能得到我需要做的事情,所以我会再次尝试解释。

我有对象TableViewController。从这个对象里面我调用类AlertView来显示一些警告消息。因此,警报对话框中的用户交互(密码正常,密码不是)我需要在我的openSettings中调用方法TableViewController或不调用。那怎么做呢?

1 个答案:

答案 0 :(得分:1)

如果您的TableViewController不是您的appdelegate类,则应使用TableViewController的对象来使用方法openSettings

应该是这样的,

TableViewController *newControll = [[TableViewController alloc] init];

假设您要转移到新的alertView。在AlertView.h文件中添加

@property(nonatomic, retain) TableViewController *tableViewController;

在创建新的alertView对象时,

AlertView *alertView = [[AlertView alloc] init];
//some code..
alertView.tableViewController = self;

现在在AlertView课程中,将其命名为

[self.tableViewController openSettings];

使用appdelegate不是这样做的方法。

如果你需要iOS上的一些教程check raywenderlich

相关问题