title: how to get touch event on subviews and delegate proper actions according to it
body: <p>I am a newbie in iphone developmenst its my second sample code.
  I am trying to add subViews to a View and generate events according to the view which is touched. The projects I am experimenting with is a newly created, clean Window-Base application,</p>
  
  <p>I wrote the following code into the one and only viewController's code:</p>
  
  <pre><code>@interface testViewController : UIViewController {
  
      IBOutlet UIView *redView;
      IBOutlet UIView *redView1;
      IBOutlet UIView *blueView;
  
  }
  
  //---expose the outlet as a property---
  @property (nonatomic, retain) IBOutlet UIView *redView;
  @property (nonatomic, retain) IBOutlet UIView *redView1;
  @property (nonatomic, retain) IBOutlet UIView *blueView;
  
  //---declaring the action---
  -(IBAction) viewClicked: (id) sender;
  
  @end
  </code></pre>
  
  <p>And its .m file contains an action responder.what i am trying to do is when my views are touched they will generate an event which should be treated by this single method which will change the backcolor of the redview accordingly.</p>
  
  <pre><code>-(IBAction) viewClicked:(id) sender {
      redView.backgroundColor = [UIColor blackColor];
  }
  </code></pre>
  
  <p>i worte the delegate in this way</p>
  
  <pre><code>    @interface testAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
      UIWindow *window;
      testViewController *viewController;
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet testViewController *viewController;
  
  @end
  </code></pre>
  
  <p>In testAppdelegate.m i am making views and subviews accoring to it and they are displaying it very well but i am unable to get any events on it when they are touched in (viewClicked:)
  method.How to do this????</p>
  
  <pre><code>- (void)applicationDidFinishLaunching:(UIApplication *)application {    
  
      // Override point for customization after application launch
      window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      window.backgroundColor = [UIColor whiteColor];
  
      // Create a simple red square 
      CGRect redFrame = CGRectMake(0, 10, 320, 100);
      UIView *redView = [[UIView alloc] initWithFrame:redFrame];
      redView.backgroundColor = [UIColor redColor];
      //-------------------------------------------------------------------------------------------------------   
      // Create a simple blue square
      CGRect blueFrame = CGRectMake(5, 115, 100, 100); 
      UIView *blueView = [[UIView alloc] initWithFrame:blueFrame]; 
      blueView.backgroundColor = [UIColor blueColor];
  
      // Create a simple blue square
      CGRect blueFrame1 = CGRectMake(110, 115, 100, 100); 
      UIView *blueView1 = [[UIView alloc] initWithFrame:blueFrame1]; 
      blueView1.backgroundColor = [UIColor blueColor];
  
  
      // Add the square views to the window
      [window addSubview:redView];
      [window addSubview:blueView];
      [window addSubview:blueView1]; 
  
      [window addSubview:viewController.redView];
      [window addSubview:viewController.blueView];
          [window addSubview:viewController.blueView1];
  
      [window makeKeyAndVisible];
  }
  </code></pre>
  
  <p>Thanks</p>