您好,我在 xcode 中收到“需要左值作为赋值的左操作数”错误。为什么? 这是我的代码(window1/2 是 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];
}
感谢您的帮助。
最佳答案
self.window2.view.frame
部分将留给您一个 getter,而不是真正进入并抓取 内部框架 CGRect
.您需要做的是让 CGRect
更改它,然后将其重新设置到 View 中。
CGRect f = self.window2.view.frame; // calls the getter
f.origin.x = 320;
self.window2.view.frame = f; // calls the setter
关于iphone - 需要左值作为赋值的左操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1998558/