在 iOS 中从 ParentViewController 调用 SEL
我有一个 ViewController,在其中创建了一个模态 ViewController。我的模态中有一个 SEL 值,是在从父级实例化它时设置的。
setDateViewController.selectorName = @selector(myMethod:);
在我的模态中,我尝试将此 SEL 称为:
[[self parentViewController] performSelector:self.selectorName withObject:selectedDate afterDelay:.5];
{selectedDate} 显然是我的模态中的值。
我没有收到任何错误或堆栈,但是,我的父级上的这个 SEL(方法)从未被调用。出于某种原因,我认为这应该可行,但有件事告诉我我已经偏离了轨道。
谢谢。
I have a ViewController in which I create a Modal ViewController. I have a SEL value in my modal that I set when it is being instantiated from the parent.
setDateViewController.selectorName = @selector(myMethod:);
In my modal I am trying to call this SEL like:
[[self parentViewController] performSelector:self.selectorName withObject:selectedDate afterDelay:.5];
{selectedDate} is obviously a value from my modal.
I don't get any errors or stack, however, this SEL (method) on my parent is never being called. For some reason I think this should work, but something tells me I'm way off track.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜 [selfparentviewcontroller] 没有返回任何内容。
尝试 UiviewController* v = [selfparentviewcontroller];并检查是否为零。最有可能它应该是零。否则,如果它指向不同类的另一个对象,那么它就会崩溃。请做一件事。您应该将 bot 设置为您需要调用的对象和方法。如果有任何问题,IT 部门都会解决。
从父类中这样调用。因此您可以动态指定要调用的方法和对象,从而提供了更大的灵活性。
并使用,
[selectorDelegate PerformSelector:self.selectorName withObject:selectedDate afterDelay:.5];
这应该可以解决任何问题。
I guess [self parentviewcontroller] is not returning anything.
Try UiviewController* v = [self parentviewcontroller]; and check if is nil. Most probably it should be nil. Else if its was pointing to another object of different class then it would have crashed. Please do one thing. YOu should set bot the object and the methd you need to call. IT will solve any issues if it has any.
call like this from parent class. So you can dynamically specify the method and the object you want to call gives more flexibility.
and use,
[selectorDelegate performSelector:self.selectorName withObject:selectedDate afterDelay:.5];
this should solve any issues.
也许您会考虑向您的模式添加委托协议,以允许它调用父级上的方法。
快速(未经测试)示例:
只需确保在创建模态控制器时将其委托设置为父级上的 self :
Perhaps you would consider added a delegate protocol to your modal that will allow it to call the method on the parent.
Quick (untested) example:
Just make sure when you are creating your modal controller you set it's delegate to self on the parent: