开发者

Object don't call the good controller

开发者 https://www.devze.com 2023-01-12 08:26 出处:网络
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. I want a put this toolBar in a lot of vi

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. 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. So I create a UIViewController with a nib file, this nib file containt my toolBar. Now, in a uiview, I do this

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".

How I can go in the "toolBar.m" method?


The problem is not the release (assuming that your original viewController and its associated view are still around). 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

[objToolBall addTarget:action:forControlEvents:]

and then remove those objects as listeners with matching calls to -removeTarget:action:forControlEvents.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号