mardi 5 mai 2015

ios How to know which UIView when I click from xib?

Because some reasons, I create a UIView xib file to reuse.
How to know which UIView when I click from xib?

I create a xib file extends UIView(named with XibView).
Then I drag two UIView(leftView,rightView) in the storyboard, and set the custom class "XibView" in XCode inspector window.

When I compile the code, It will get correct result that show two UIViews.

XibView.m file part code below:

 -(id) initWithCoder:(NSCoder *)aDecoder
 {
     self = [super initWithCoder:aDecoder];

     if( self )
     {

          UIView *containerView = [[[UINib nibWithNibName:@"XibView" bundle:nil] instantiateWithOwner:self options:nil] objectAtIndex:0];
          CGRect newFrame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
          containerView.frame = newFrame;
          [self addSubview:containerView];
     }
    return self;
 }

 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
      NSLog(@"tap in xib");
      ......
 }

But How can I know which UIView is my click?

// I add some detail description.

In the xib custom class, I will using post the notify to the uiviewcontroller and take some data when user click in xib(touchesBegan is in the xib custom class).

I have two uiview in the storyboard , these uiview will using the xib file.

so I want to know when I click which uiview, I can know which one user click.

Aucun commentaire:

Enregistrer un commentaire