Haga clic en el botón UIB, mientras que NIB se carga desde otro archivo XIB

I have a View (called MyView) in my Layout file. I want to content to be loaded from another XIB file (called FooterView). This works fine, this way:

NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:self options:nil];
UIView *footerView = [subviewArray objectAtIndex:0];
[MyView addSubview:footerView];

But what if I have a button in my FooterView, with the Retoque en el interior linked to a IBAction in my FooterView.m class? At the moment, when I click on the button, I'm receiving this error: selector no reconocido enviado a la instancia

It would be great if I can catch the button click in the FooterView.m class. How can I get this done?

Edit: I now have the following problem: I want to change the view from My FooterView class (which inherits from UIView) like this:

NewView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:distilleryView animated:YES];   

Where NewView is a UIViewController. I can't call presentModalViewController from a View. I also tried getting the parentclass from self, but that doesn't work either.

¿Cómo puedo hacer que esto funcione?

preguntado el 02 de febrero de 12 a las 11:02

have you define the IBAction method in your FooterView.m? -

@MuditBajpai I did, I have an IBAction in my .h and .m file, and connected this one using the Interface Builder. -

1 Respuestas

Have you tried to set the file's owner to
FooterView in xib like this one

enter image description here

Respondido 02 Feb 12, 15:02

One doubt: how he can give footerViewObj as owner when he is getting UIView *footerViewObj = [subviewArray objectAtIndex:0]; after that initialization of subviewArray - Adil Soomro

yesh Adil you are right I just got confused... now edited my answer again - Inder Kumar Rathore

It doesn't work when I set the Custom Class to FooterView, still receiving the same error. It does work though when I do it like your unedited comment: FooterView *fv = [[FooterView alloc] init]; NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:self options:nil]; UIView *footerView = [subviewArray objectAtIndex:0]; [currentFooter addSubview:footerView]; - harmjanr

@InderKumarRathore I made an edit to my first post. Do you have any idea? - harmjanr

Nevermind, I fixed it making a custom constructor, that needs the UIViewController. I save the UIViewController in the FooterView class as UIViewController *parent. Right now, I can say [parent presentModalViewController:distilleryView animated:YES]; - harmjanr

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.