Discuss Cross-Class Methods at the iPhone Developer Exchange - Hackint0sh.org; Hey Everyone,
I'm new to Objective-C, but picking it up quickly. I've been working on ...
I'm new to Objective-C, but picking it up quickly. I've been working on an official app for the app store, but I'm having an annoying problem that I don't know how to fix.
I have the App Delegate, which creates several instances of a UIViewController called RootViewController, which creates one MainViewController per RootViewController.
The issue is that I want to call a method of the App Delegate called toggleView (Yeah, I'm using a bit of Apple example code ), but whenever I try to call it ([AppDelegate toggleView], it fails. I realized that this is because it's looking for a + (public?) method instead of a - (private?) one. However, when this function is public, it cannot access several instance variables, and the app crashes whenever the class toggleView is called from MainView. XCode warns that "instance variable '(insert name of variable here)' accessed in class method".
So, how can I fix this? I really need help, and it's really bugging me.
Thanks so much!
No, + doesn't mean it's public. It means that you can run that method without having an allocated/initialized instance of the class.
If you add your
- (void) toggleView;
to the appDelegate.h header, it'll be publicly available.
If you needed it to be private, you'd add this to the appDelegate.m :
interface appDelegate (Private)
- (void) toggleView;
Hope this helps you a tiny bit..
Your appDelegate gets initialized through your main .xib file when main.m calls UIApplicationMain.
If you open that .xib, you should have an object that is of your appDelegate class. If it's there, it's initialized automatically.
Does the app crash upon launch, or when you "toggle your view"?
Have you tried adding a breakpoint before the toggleView kicks in, and step through the lines, to see exactly where it crashes?
Last edited by TheBrew; 09-20-2008 at 12:32 PM.
The xib does contain my delegate class. The app doesn't crash until the view is toggled (triple tap)
Originally Posted by TheBrew
I haven't added a breakpoint, but I NSLogged on a couple of lines and found out that it crashes as soon as the method is called if it's -, or if it's +, it crashes on the line UIView *mainView = controller.view; (controller is an instance of RootViewController)
What does it say in the debugger console?
Got a stacktrace or error?
There's a number of things that could be going on. Maybe it's not declared. Maybe it's not hooked up. Maybe you're trying to get to it before the nib finished initializing. Maybe somebody freed it.
By hackint0sh in forum Latest Headlines
Last Post: 04-29-2009, 08:00 PM
Last Post: 09-14-2007, 09:23 AM
By HiSoC8Y in forum General
Last Post: 09-09-2007, 12:37 AM