2010-03-31 74 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"); 
相关问题