Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slking

macrumors newbie
Original poster
Aug 15, 2008
3
0
I am very-much new to the iphone programming. I want to swap the view of a UIViewController as the iphone rotates. I have these methods implementd in my view controller. i get syntax error in the line "self.view = landscapeView".

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;// for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = landscapeView;
}

if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portraitView;
}
}
 
try:-

Code:
self.view = [landscapeView self];

and

Code:
self.view = [portaitView self];

repectively

OR it that fails try:-

Code:
[self setView:[landscapeView self]];

and

Code:
[self setView:[portraitView self]];

respectively
 
Thanks for the reply.
I tried both methods mentioned above. But
Code:
[self setView:[landscapeView self]];
and
Code:
self.view = [landscapeView self];
Gave
"Error:landscapeView undeclared (first use in this function)"

I have two UIView objects declared in the
Code:
@interface MyCalViewController : UIViewController {
	UIView	*p;
	UIView	*l;
}

@end

and in the MYCalViewController.m
Code:
- (void)loadView {
	self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
	p = [self portraitView];
	l = [self landscapeView];
	
	UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
	if (orientation == UIInterfaceOrientationPortrait) {
		[self.view addSubview:p];
	}
	else {
		[self.view addSubview:l];
	}}

So is there anything that i am doing wrongly or should i do something else to get this done?
 
According to Master Nilson, the correct approach is to replace this line:

Code:
return (interfaceOrientation == UIInterfaceOrientationPortrait);

with this line:

Code:
return YES;
 
According to Master Nilson, the correct approach is to replace this line:

Code:
return (interfaceOrientation == UIInterfaceOrientationPortrait);

with this line:

Code:
return YES;
...assuming you want to support all four orientations. Otherwise, only return YES for orientations you want to support.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.