casting problem

Discussion in 'iOS Programming' started by McBgnr, Jul 2, 2010.

  1. macrumors regular

    Joined:
    Apr 13, 2009
    #1
    Hello,

    In my program I want to cast a view to another. I write like this in viewDidLoad:

    Code:
    MyView *myView = (MyView *) self.view;
    [myView display];
    But when I call display I am getting unrecognised selector and on printing myView with NSLog I get UIView Object, instead of MyView.

    I am not able to identify what is going wrong here. Pls suggest if there is any error here.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Where do you create the object you assign to self.view? Most likely that is where the error is.
     
  3. thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #3
    Thanks, that helped me figure it out. It had to be changed to MyView in the IB.


    Another thing that I am facing a problem is that I want to use iPhone size view in a iPad application. But that view is not autoresizing. Any idea what has to be done?
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Have you set the autoresizing mask, either in IB or in the code?
     
  5. thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #5
    Yes Autoresize Subviews is checked in IB. Still it is not getting resized. All the labels in the View display very small font instead of the one that I have set in IB.
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    It may be that you need to tell the view to size correctly on the iPad depending on the controller type it's loading into. With regards to the fonts are you using ones that actually exist on the target device?
     
  7. thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #7
    Thanks for the quick response.

    I have no idea how to tell the view to size correctly on the iPad? any pointers will be helpful.

    I am only checking on the simulator now. So font should be there.
     
  8. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    How is the view being loaded and presented? I assume you are using a view controller? Regardless I would look at setNeedsLayout.

    For what it's worth I'm in the early stages of porting one of my apps to the iPad and my views just work in a UISplitView...
     
  9. thread starter macrumors regular

    Joined:
    Apr 13, 2009
    #9
    Yes, I am using a View controller. I will take a look at setNeedsLayout and see if it is working.
     
  10. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #10
    This isn't the answer

    to this question

    Code:
    Have you set the autoresizing mask, either in IB or in the code?
    You need to set the autoResizingmask property, in IB with the springs and struts or in code. Have you done that and is it not working the way it should?
     

Share This Page