2011-09-10 132 views
0

访问视图我有一个窗口4视图。所有视图链接,以同样的方法 - (IBAction为)触动:(ID)发送如何从IBAction为方法

触摸时,在图1只图1种的背景颜色是变化如何我做。 但左3视图没有。 另外,如果我触摸另一视图仅查看触摸变化的背景色,但其它视图不会改变。

谢谢

回答

1

你应该实现你的UIViewController

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    if([event touchesForView:view1] != nil) 
     //View1 touched 
    else if ([event touchesForView:view2] != nil) 
     //View2 touched 
    else if ([event touchesForView:view3] != nil) 
     //View3 touched 
    else if ([event touchesForView:view4] != nil) 
     //View4 touched 
} 
+0

我已尝试但它不工作。 – MAXZZXAM

0

您可以通过设置“标签”性质,并在您(IBAction为)标签视图触及-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event方法:(ID)发送者你检查标签值,如

if (((UIView*)sender).tag == 1) { 
    //Do something for the view with tag value 1 
}