我已经制作了一个名为HeartrateGraph的UIView中的数据图。在名为HRGraphInfo的UIViewController中,我有一个连接的标签,当图形被触摸时应该输出值。问题是,我不知道如何使用委托从UIView发送到UIViewController触摸的事件。如何使用touchesBegin从另一个UIViewController中的一个UIView
这里是UIView的我触摸分配代码:
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
for (int i = 0; i < kNumberOfPoints; i++)
{
if (CGRectContainsPoint(touchAreas[i], point))
{
graphInfoRF.heartRateGraphString = [NSString stringWithFormat:@"Heart Rate reading #%d at %@ bpm",i+1, dataArray[i]];
graphInfoRF.touched = YES;
break;
}
}
这个代码段是一个的touchesBegan并妥善保存在对象graphInfoRF的数据值和号码(我只是没有显示的声明dataArray,kNumberOfPoints等)。
我能够访问graphInfoRF在UIViewController中使用:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (graphInfoRF.touched == YES) {
self.heartRateLabel.text = graphInfoRF.heartRateGraphString;
}
else {
self.heartRateLabel.text = @"No data got over to this file";}
}
标签将显示正确的字符串,但图表中的数据点被触摸并且只有在标签后立即感动。如何更改touchesBegan,以便一旦我触摸图上的数据点,它就会自动填充标签,而不需要在标签上再次单独触摸?
我建立了我的项目最初的方式是因为有些低效该图是一个单独的'UIView',但我太过于改变格式。将我的活动传递给超级观点只是一招。非常感谢! – momodude22