n00b subclassing question

Discussion in 'iOS Programming' started by darthtroll, Feb 17, 2011.

  1. darthtroll macrumors newbie

    Joined:
    Aug 24, 2010
    #1
    So I've got this UIView subclass that delegates methods from UIPickerView and UITableView etc...is it a bad programming practice in Coca to subclass this subclass?

    Would my subclass also need delegate methods (assuming the logic isn't being changed)? In other words, is it mandatory? I'm planning on using about 5 different views across my tableViewController and I was debating having one ginormous class that has all the layout logic layed out and a bunch of "if" statements to decide the right methods to call for the 5 views.

    OR I can create just a class that has all the layout logic and subclass that for different methods that should be called. What is the best and/or common practice?

    Darthtroll
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Why is your view acting as a controller. Normally objects in your controller layer would be the delegate to other views...
     
  3. darthtroll thread starter macrumors newbie

    Joined:
    Aug 24, 2010
    #3
    Apologies, I meant UIViewController subclass.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    OK. Well normal subclassing rules apply. If you don't know what these are then stop programming and go and find out: this is a core piece of knowledge you need to have. In short any method you don't override in your subclass will automatically be inherited from the superclass.
     
  6. amorya macrumors 6502

    Joined:
    Jun 17, 2007
    #6
    While Cocoa programmers often don't create as deep a class hierarchy as in some other languages/APIs, that doesn't mean you can't subclass at all. If it means you write less and/or more readable code, go ahead and subclass :)
     

Share This Page