总的来说,我对编程相当陌生,并且一直在关注 iTunesU 上的 CS193p 视频。我目前正在执行任务 3,并且无法从发送到视图控制器的视图中获取一些信息。
我相信我已经正确设置了整个委托,所以问题实际上是如何让我的 View Controller 看到一些信息(例如self.bounds.size.width
),这是只有 View 才有的属性。这会涉及使用self.dataSource
吗?如果是这样,我可以通过什么方式传递这些信息?我的最终目标是让 View Controller 对 View 的属性进行一些转换,然后将其发送回 ViewdrawRect
以便绘制。
谢谢!!
** 根据要求编辑,我在下面发布了我的 drawRect 代码的一部分
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat scale = 32;
CGPoint midPoint;
midPoint.x = self.bounds.origin.x + self.bounds.size.width/2;
midPoint.y = self.bounds.origin.y + self.bounds.size.height/2;
// ---- finding the y starting point
float totalXsInWidth;
totalXsInWidth = self.bounds.size.width / scale;
float leftMostX = totalXsInWidth / -2;
float graphResultY = sin(leftMostX); // ** in theory, I want "leftMostX" to be modifed by the equation entered (in the CONTROLLER)
NSLog(@"The leftMostX is %f", leftMostX);
[self.dataSource passingVariable:leftMostX]; //** Here I pass the variable from drawRect to get modifyed in the CONTROLLER
float graphResultY1;
graphResultY1 = 5; //this is a test, I want to see if the controller actually effect a change
graphResultY1 = [self.dataSource calcResult:self]; //this should now be a different number than 5 or 0 (the init value)
NSLog(@"From graphingview, the result is %f", graphResultY1); //** unfortunately = 0... :(