Re: [問題] 兩個class之間互動問題
: GameViewController是我主要元件的class
: dragView是拖曳圖片動作的class
: /*dragView*/
: - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
: BOOL find = NO;
: GameViewController *ccc =[[GameViewController alloc] init];
這邊 init 了一個GameViewController ccc (稱為ccc_A)
: for (UIImageView *view in [[self superview] subviews]) {
: if (view.tag != -1 && CGRectIntersectsRect(dragView.frame, view.frame))
: [view setBackgroundColor:[UIColor clearColor]];
: [dragView removeFromSuperview];
: [ccc setScoreLabel];//設定計分板
這邊讓 ccc_A 執行方法
: find = YES;
: }
: }
: if (!find) {
: [self returnAnimation];
: }
: }
: /*GameViewController*/
: - (void)setScoreLabel{
: score += 100;//有執行到這一行 (稱為 line_X
這只能說明有"一個" GameVC 物件執行了這段方法(我猜是ccc_A)
: ScoreLabel.text = [NSString stringWithFormat:@"%d",score];//卻沒執行這一行
: }
問題在於,ccc_A 是你畫面上的那一個 GameViewController (假設是ccc_O) 嗎?
ccc_A 執行了 line_X, 改變了 ccc_A 自己的ScoreLabel 內容
但是 ccc_A 並不是你畫面上的那一個 ccc_O
我猜這是為何你會覺得 明明 line_X 有執行到
但是 ccc_O 的內容沒有改變的原因
因為 dragView 一直init 新的 ccc, 每個 ccc都會執行 line_X
改變自己的 ScoreLabel
然後就....沒有然後了 XD
所以大家才會問你 reference 到哪一個之類的問題
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.20.53
→
06/19 14:49, , 1F
06/19 14:49, 1F
推
06/19 14:54, , 2F
06/19 14:54, 2F
推
06/19 15:15, , 3F
06/19 15:15, 3F
→
06/19 15:18, , 4F
06/19 15:18, 4F
→
06/19 15:35, , 5F
06/19 15:35, 5F
→
06/19 15:35, , 6F
06/19 15:35, 6F
→
06/19 15:36, , 7F
06/19 15:36, 7F
推
06/19 15:36, , 8F
06/19 15:36, 8F
→
06/19 15:38, , 9F
06/19 15:38, 9F
→
06/19 15:39, , 10F
06/19 15:39, 10F
推
06/19 15:41, , 11F
06/19 15:41, 11F
→
06/19 15:51, , 12F
06/19 15:51, 12F
→
06/19 15:56, , 13F
06/19 15:56, 13F
推
06/19 16:44, , 14F
06/19 16:44, 14F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
2
23
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章