Reputation: 1890
Hello I get the "Lvalue required as left operand of assignment" error in xcode. Why? Here is my code (window1/2 are UIViewController) :
- (void)loadView
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,460)];
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,640,460)];
self.window1 = [TweetViewController alloc];
self.window2 = [InfoViewController alloc];
[contentView addSubview:self.window1.view];
self.window2.view.frame.origin.x = 320; //HERE IS THE ERROR!!
[contentView addSubview:self.window2.view];
[scrollView addSubview:contentView];
scrollView.contentSize = contentView.frame.size;
scrollView.pagingEnabled = YES;
self.view = scrollView;
[contentView release];
[scrollView release];
}
Thanks for your help.
Upvotes: 5
Views: 3760
Reputation: 11880
This is kind of advanced (or experimental...); you should understand this problem, and do it the regular way (à la epatel) a bunch until you have it cold.
But I have a macro that lets you do this
@morph(self.window2.view.frame, _.origin.x = 320);
[contentView addSubview:self.window2.view];
Upvotes: 0
Reputation: 70234
You have to set the frame as a whole:
CGRect f = self.window2.view.frame;
f.origin.x = 320;
self.window2.view.frame = f;
See properties.
Upvotes: 2
Reputation: 46041
The part self.window2.view.frame
will leave you with a getter, not actually reaching into and grabbing the internal frame CGRect
. What you need to do is get the CGRect
change it and then set it back into the view.
CGRect f = self.window2.view.frame; // calls the getter
f.origin.x = 320;
self.window2.view.frame = f; // calls the setter
Upvotes: 15