1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Subclassing a UIViewController subclass

Discussion in 'iPhone/iPad Programming' started by MihaiD, Jan 12, 2009.

  1. macrumors newbie

    #1
    I have a UIViewController subclass and a xib file who's owner is set to the former. Now I need to subclass the first UIViewController subclass to add some specific behavior. However when I try to push an instance of the UIViewControllers subclass-subclass on the UINavigationController my program stops.

    Any ideea on what I could be doing wrong? Do I need different xib's for the two classes?

    Thanks
     
  2. macrumors regular

    #2
    Hey MihaiD,

    You will need to create another XIB with the second subclass as the File's Owner.

    Let's say you have subclass B which is a subclass of A. You instantiate an instance of A. In this scenario you have NO access to any methods or properties declared in B.

    However, if you do it the other way around, you instantiate an instance of B, then you have access to everything in B and A(unless you make stuff private...). Make sense?

    So, maybe you want your file's owner in the first xib to be subclass B?
     
  3. Guest

    caveman_uk

    #3
    I don't think that's strictly correct. You should be able to use a xib that has as it's File's Owner the parent class, with a subclass so long as you don't have anything in that xib that refers to the subclass. I've done it and it does work.
     
  4. macrumors regular

    #4
    I see what your saying. I think it is feasible as you initialize the file owner separately from the xib. What is the error your getting? Have you tried stepping through the process?
     
  5. macrumors 6502a

    #5
    Out of interest, what exactly are you trying to do, and have you considered using composition to vary behaviour rather than inheritance?
     
  6. macrumors newbie

    #6
    @Spike099

    I am not trying to refer to anything in the subclass' subclass. In fact that class is pretty much empty for now. What I'm getting is a NSInvalidArgumentException

    @Luke Redpath

    I'm not sure composition would help me. I'm trying to reuse most of the functionality from my first UIViewController subclass
     
  7. macrumors newbie

    #7
    OK, found the problem. My superclass was relying on a certain member parameter being set and I forgot to do that. It all works now.
     

Share This Page