나는 일반적으로 프로그래밍에 익숙하지 않으며 iTunesU에서 CS193p 비디오를 따라 왔습니다. 현재 과제 3을 수행하고 있으며 View Controller로 보낸 View에서 약간의 정보를 얻는 데 문제가 있습니다.iOS - VIEW에서 컨트롤러로 정보를 전달하는 방법은 무엇입니까?
저는 전체 위임을 올바르게 설정했다고 생각합니다. 따라서보기가 실제로보기에만있는 속성 인 약간의 정보 (예 : self.bounds.size.width
)를 보는 방법이 문제입니다. 이것은 self.dataSource
을 사용합니까? 그렇다면 어떤 수단을 통해이 정보를 전달할 수 있습니까? 나의 마지막 목표는 뷰 컨트롤러가 뷰의 속성에 대한 일부 변환을 수행하고 그 뷰를 뷰의 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... :(
수 DUPL을 [CS193p 과제 3 - VIEW에서 View Controller로 정보를 전달하는 방법?] (http : // stackoverflow.co.kr/questions/12719329/cs193p-assignment-3-how-to-passing-info-from-view-controller) – kiamlaluno