简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM