Iphone @单独类中函数的选择器
如果我有一个在类Foo中定义的函数,并且我的类栏有一个对类Foo的引用,我可以使用@selector调用该函数吗?差不多Iphone @单独类中函数的选择器,iphone,Iphone,如果我有一个在类Foo中定义的函数,并且我的类栏有一个对类Foo的引用,我可以使用@selector调用该函数吗?差不多 @selector([Foo someFunctionInFoo:]) 我只使用@selector调用同一类中的函数。我试着做一些类似于上面代码的事情,但没有成功,我甚至不确定这是否可行。谢谢。@选择器不存储任何通话信息,只存储选择器 [Foo performSelector:@selector(someFunctionInFoo:) withObject:nil]; 您
@selector([Foo someFunctionInFoo:])
我只使用@selector调用同一类中的函数。我试着做一些类似于上面代码的事情,但没有成功,我甚至不确定这是否可行。谢谢。@选择器不存储任何通话信息,只存储选择器
[Foo performSelector:@selector(someFunctionInFoo:) withObject:nil];
您还可以执行以下操作:
Class class = SomeClass;
id obj = [class someObject];
SEL sel = @selector(someFunction);
[class performSelector:sel];
[obj performSelector:sel];
只要两者都实现某种功能
要指定按钮等使用的目标,请将目标和操作设置为两个属性,例如:
[[UIBarButtonItem alloc] initWithTitle:@"Filter"
style:UIBarButtonItemStyleBordered
target:foo // The object to send the message to
action:@selector(someFunctionInFoo:)]; // The message to send
但是,当我创建UIBarButonItem时,如何将其绑定为选择器?类似于self.ParentController.FilterButton=[[uiBarButtonim alloc]initWithTitle:@Filter style:uiBarButtonimStyleBorded目标:自我操作:@Selector FilterButtonPressed:];“target”参数指定将消息发送到哪个对象,“action”参数指定使用哪个选择器。这就是你想要在任何地方发送信息所需的全部信息。你用Foo替换self。该方法基本上是在按下条形按钮时执行[target performSelector:action]。我已经更新了我的答案,包括这个。。。