我已經制作了一個名爲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