PDA

View Full Version : casting problem




McBgnr
Jul 2, 2010, 06:06 AM
Hello,

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

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.



robbieduncan
Jul 2, 2010, 06:50 AM
Where do you create the object you assign to self.view? Most likely that is where the error is.

McBgnr
Jul 2, 2010, 07:22 AM
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?

robbieduncan
Jul 2, 2010, 07:23 AM
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?

Have you set the autoresizing mask, either in IB or in the code?

McBgnr
Jul 2, 2010, 07:49 AM
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.

robbieduncan
Jul 2, 2010, 07:50 AM
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.

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?

McBgnr
Jul 2, 2010, 07:58 AM
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.

robbieduncan
Jul 2, 2010, 08:06 AM
How is the view being loaded and presented? I assume you are using a view controller? Regardless I would look at setNeedsLayout (http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/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...

McBgnr
Jul 2, 2010, 08:12 AM
Yes, I am using a View controller. I will take a look at setNeedsLayout and see if it is working.

PhoneyDeveloper
Jul 2, 2010, 11:39 AM
This isn't the answer

Yes Autoresize Subviews is checked in IB.

to this question

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?