[英]Object don't call the good controller
In my apps, I have a toolBar with a button inside. 在我的应用程序中,我有一个工具栏,里面有一个按钮。 When you pressed that button a actionSheet appear and you can change the langage of the apps. 当您按下该按钮时,将显示一个actionSheet,您可以更改应用程序的语言。 I want a put this toolBar in a lot of view, but I want to use the same object, not copy-paste in all my view. 我希望将这个ToolBar放在很多视图中,但是我想使用同一对象,而不是在所有视图中都复制粘贴。 So I create a UIViewController with a nib file, this nib file containt my toolBar. 因此,我创建了一个带有nib文件的UIViewController,该nib文件包含我的toolBar。 Now, in a uiview, I do this 现在,在uiview中,我这样做
toolBar *objToolBall = [[toolBar alloc] initWithNibName:@"toolBar" bundle:nil];
objToolBall.view.frame = CGRectMake(0, 418, 320, 44);
[self.view addSubview:objToolBall.view];
[objToolBall release];
my problem is that when I pressed the button in the toolBar, the program try to find the method "clickButtonLanguage" in the file I create the object, and not in "toolBar.m". 我的问题是,当我按下ToolBar中的按钮时,程序尝试在我创建对象的文件中找到该方法“ clickButtonLanguage”,而不是在“ toolBar.m”中找到该方法。
How I can go in the "toolBar.m" method? 如何进入“ toolBar.m”方法?
The problem is not the release (assuming that your original viewController and its associated view are still around). 问题不在于发布(假设您的原始viewController及其关联的视图仍然存在)。 The release makes sense: you've created an object, handed off responsibility for it to the view you added it to, and now you need to release it so it doesn't leak. 该版本很有意义:您已经创建了一个对象,将对它的责任移交给了添加到它的视图,现在您需要释放它以免泄漏。 So don't drop that line. 因此,请勿删除该行。
You're getting the method invocation in your original view controller because that's exactly what you've connected it to . 您正在原始视图控制器中获得方法调用,因为这正是您将其连接到的对象 。 If you want to connect it to other IBActions
you'll have to add them programmatically with 如果您想将其连接到其他IBActions
,则必须以编程方式添加它们
[objToolBall addTarget:action:forControlEvents:]
and then remove those objects as listeners with matching calls to -removeTarget:action:forControlEvents
. 然后通过与-removeTarget:action:forControlEvents
匹配调用将这些对象作为侦听器除去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.