Results 1 to 6 of 6
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 ...
  1. #1
    Professional Array

    Join Date
    Sep 2006
    Posts
    53
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    10

    Default Cross-Class Methods

    Hey Everyone,

    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!



  2. #2
    Rookie Array

    Join Date
    May 2008
    Posts
    15
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    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;
    @end

    Hope this helps you a tiny bit..

  3. #3
    Professional Array

    Join Date
    Sep 2006
    Posts
    53
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    10

    Default

    Quote Originally Posted by TheBrew View Post
    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;
    @end

    Hope this helps you a tiny bit..
    Hmm... the - (void)toggleView; line is already in my header, but the app crashes if it's - and not +. So I guess there's no initialized instance of the class? I don't quite understand how this works - the app seems to jump directly to the delegate class, however I don't see where it decides to jump to this class - main.m does not mention it. Is there some way I can initialize the class before jumping to it? Although I'd assume it already is... I mean, it's running... Very confused

    Thanks for the help!

  4. #4
    Rookie Array

    Join Date
    May 2008
    Posts
    15
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    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.

  5. #5
    Professional Array

    Join Date
    Sep 2006
    Posts
    53
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    10

    Default

    Quote Originally Posted by TheBrew View Post
    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?
    The xib does contain my delegate class. The app doesn't crash until the view is toggled (triple tap)

    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)


  6. #6
    Senior Professional Array

    Join Date
    Jul 2007
    Posts
    151
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    16

    Default

    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.

 

 

Similar Threads

  1. MacNN: Imation ships, prices M-Class and S-Class SSDs
    By hackint0sh in forum Latest Headlines
    Replies: 0
    Last Post: 04-29-2009, 08:00 PM
  2. Replies: 2
    Last Post: 09-14-2007, 09:23 AM
  3. Replies: 2
    Last Post: 09-09-2007, 12:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin®
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO
(c) 2006-2012 Hackint0sh.org
All times are GMT +2. The time now is 08:21 PM.
twitter, follow us!