Question

I have Class A which contains a xib with some buttons and a UITextField and Class B which contains a tableView I want to add Class A to the table view header.

I am importing the xib from class A into class B using [[[NSBundle mainBundle] loadNibName: owner:self options:nil] objectAtIndex:0];

I just want to reflect the button and textview actions inside classB. In ClassB I do have some UITextfield Delegate methods which i expect to be called when typing some text in uitextfield defined and declared in ClassA (xib + property definition in .h file).

Class A .h:

//properties are set from xib file ClassA.xib
@interface ClassA : UIView

@property (unsafe_unretained, nonatomic) IBOutlet UIButton *addC; 
@property(strong, nonatomic) IBOutlet UITextField *nText;

@end

Class B.h

#import "ClassA"
@interface ClassB : UIViewController <UITextFieldDelegate, UITableViewDataSource,...>

@property (strong, nonatomic) IBOutlet UITableView *mTableView; //property set from ClassB.xib
@property(strong, nonatomic) IBOutlet UITextField *nText_B;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *addC_B;

- (IBAction)addC:(UIButton *)sender;
@end

I don't know how to make the link ClassB button and textfield to ClassA In ClassB viewDidLoad method i;ve tried this:

 getHeader = [[ClassA alloc]init];
   _addC_B = [getHeader addC];
   _nText_B = [getHeader nText]; 
    _nText_B.delegate =self;
    _nText_B.text=@"";

but it's not working I am new to iOS on this side area. Thank you for your help

Was it helpful?

Solution

You haven't explained your problem well. Classes do not "contain xibs".

If your objective is to create a piece of user interface in XIB and reuse it, you can achieve this with [NSBundle loadNibNamed:owner:options:]. The best way to reference parts of it is through properties like Noval explained in his answer. Another possibility is to attach views to "File's Owner" outlet's properties.

OTHER TIPS

you can't connecting IBOutlet that placed outside your XIB class. but if you just want to access the outlet from other class, it's possible by creating instance of ClassA in ClassB. and then accessing the property like instanceOfClassA.outletObject

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top