2012-11-08 59 views
0

我是新来的目标C,并试图掌握代表的方法和用法。目前我有Alertview类,我需要它来创建另一个类来调用它的功能。我设法与appdelegate类一样。但是不能和我自己的班级一起做。无法使用委托

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

这就是我正在尝试访问我的方法。 Compilator在newControll中看到这个方法,但是调用这个方法会得到unrecognizet选择器。基本上,我需要从另一个类调用其中已经创建的函数。我很抱歉,如果这是一个简单的解决方案,但我不能完全掌握delegate和objective-c。

也许不是每个人都得到了我需要做的,所以我会试着再解释一次。我的对象TableViewController。从这个对象里面我呼叫类AlertView显示一些警报消息。并因此在警报对话框中的用户交互(密码是好的,密码不是)我需要拨打我的TableViewController中的方法openSettings或不打电话。那么如何做到这一点?

+0

我不知道你想要,但编译器说起事情..)起初 - 你确定[UIApplication sharedApplication] .delegate是不是零?第二个 - [UIApplication sharedApplication] .delegate可能没有任何选择器openSettings。 –

+0

它会帮助你发布一些代码! – footyapps27

+0

你想看哪个部分? – Datenshi

回答

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类,称呼其为,的appdelegate的

[self.tableViewController openSettings]; 

使用率不要做到这一点。

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

+0

尝试过这种方式,但它没有正确地完成它,因为我需要对之前创建的确切对象进行调用,而不是创建新对象并拨打电话。 – Datenshi

+0

newControll在哪里创建?在哪个级别?你想在哪里调用这个方法?反正更新了我的答案。 – iDev

+0

我已经更新了我的问题,请看看,也许它会更清楚我正在尝试做什么 – Datenshi