2010-03-31 73 views
0

我必須調用視圖控制器中存在的方法,該視圖控制器的引用在視圖中可用。當我嘗試像任何其他方法一樣調用方法時,出於某種原因,iPhone只是忽略了該調用。有人可以解釋爲什麼會發生這種情況,我該如何去調用這種方法呢?從視圖調用視圖控制器中的方法


在視圖中我有這樣的方法:

-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event{ 
NSArray* mySubViews = [self subviews]; 
for (UITouch *touch in touches) { 
    int i = 0; 
    for(; i<[mySubViews count]; i++){ 
     if(CGRectContainsPoint([[mySubViews objectAtIndex:i] frame], [touch locationInView:self])){ 
      break; 
     } 
    } 
    if(i<[mySubViews count]){ 
        // viewController is the reference to the View Controller. 
     [viewController pointToSummary:[touch locationInView:self].y]; 
     NSLog(@"Helloooooo"); 
     break; 
    } 
} 

}

每當觸摸事件被觸發,Hellooooo被印在控制檯但在此之前,該方法會被忽略

+0

你可以張貼一些代碼? – itsmatt 2010-03-31 17:12:11

回答

0

在視圖中我有這種方法:

-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event{ 
NSArray* mySubViews = [self subviews]; 
for (UITouch *touch in touches) { 
    int i = 0; 
    for(; i<[mySubViews count]; i++){ 
     if(CGRectContainsPoint([[mySubViews objectAtIndex:i] frame], [touch locationInView:self])){ 
      break; 
     } 
    } 
    if(i<[mySubViews count]){ 
        // viewController is the reference to the View Controller. 
     [viewController pointToSummary:[touch locationInView:self].y]; 
     NSLog(@"Helloooooo"); 
     break; 
    } 
} 

}

每當觸摸事件被觸發時,Hellooooo獲取打印在控制檯但在此之前,該方法被簡單地忽略

+0

我把它複製到你的問題中,以保持它。 – itsmatt 2010-03-31 17:49:23

+0

謝謝馬特......我對這個地方比較陌生...... :) – Lakshmie 2010-03-31 17:51:25

0

我創建的視圖的視圖控制器和所允許的視圖控制器之間的通信。也許這是MVC協議的一部分。

+0

如果這是你問題的一部分,請編輯問題而不是把它放在答案中。 – progrmr 2010-04-01 00:47:15

0

檢查它是用於確保的viewController在點值它不是零,使用調試器或添加的NSLog:

[viewController pointToSummary:[touch locationInView:self].y]; 
NSLog(@"viewController=%@", viewController); 
NSLog(@"Helloooooo"); 
相關問題