How can I inheritance an UIWebView from an UIViewController subclass?

Discussion in 'iOS Programming' started by guydor, Jun 8, 2010.

  1. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    If I understand your question correctly (you can't "inheritance" from anything: that does not make grammatical sense) then you can't. There is no way to subclass two super-classes (in Objective-C).

    On a more general note this does not make architectural sense. One is a view, the other is a controller. They should not be the same object anyway.
     
  2. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #3
    Thanks for your reply, I have another question:

    How can I inheritance the UIWebView url into another UIViewController?
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I cannot understand what you want to do. The word inheritance simply can't be used in that way. Please re-formulate your question so that it makes sense.
     
  4. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #5
    First, thanks for your patience

    :)
    My question is:
    I have an UIWebView in UIViewController class A.
    I create a string wich gets the UIWebView url;

    I want to use this string in UIViewController class B;
    How can I do this?
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    You have classes or instances? I assume instances. Your UIViewController instance A should pass the value to instance B. I suggest you implement a method in B that allows for this.
     
  6. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #7
    Can you give me an example please?

    How do I do it?
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    I just told you. If you mean "can you write my code for me?" then the answer is no. Copy and pasting my code is not programming. You need to write the code yourself.
     
  8. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #9
    I appreciate your honesty

    But what I meant is:

    How do I implement it?
    What does it mean?
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    Without being unkind if you don't understand how to implement a method in one class and call that method on an instance then you need to stop programming right now, go back a few steps and learn the language. Once you've done that study the documents on designing an application correctly. Then you can design the classes you need for the application you want. Finally you can write some code.

    I honestly can't help you more than that: basic understanding must come first.
     
  10. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #11
    Here's what I think you're asking:
    1. I have class Blarf (with files Blarf.m and Blarf.h).
    2. Somewhere I create an instance Blarf *myBlarfA.
    3. I want myBlarfA to create a myBlarfB with a URL that myBlarfA knows.

    If so:
    Create an instance variable NSURL *myURL in class Blarf.
    Use @property or write your own setters and getters.
    In step 3 above, either:
    myBlarfB.myURL = the special URL;
    or
    [myBlarfB setMyURL] = the special URL;

    To confuse things more, if you don't have a myBlarfB, maybe you want:
    [self setMyURL] = the special URL;

    But the other guy's suggestion is probably better - if you're new to Cocoa, Objective-C and OOP, then grab a book and work through a couple of chapters.
     

Share This Page