How can i access view from IBAction method
I have 4 view in a windows. All view link to same method -(IBAction)touched:(id)sender
how can i make when touch at view 1 only view 1 background color is change. but the left 3 view are not. also if i touch another v开发者_如何学Goiew only view that touching change background color but other view is not change.
thank you
You should implement -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
method of your 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
}
You can tag your view by setting its 'tag' property and in your (IBAction)touched:(id)sender you inspect the tag value like
if (((UIView*)sender).tag == 1) {
//Do something for the view with tag value 1
}
精彩评论