In View Controller.m
@interface ViewController ()
{
CustomView *view;
}
@implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
view = nil;
view = [[CustomView alloc]init];
[self.view addSubview:view];
}
In CustomView.m
-(CustomView *)init
{
CustomView *result = nil;
result = [[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil] objectAtIndex:0];
return result;
}
I have two buttons in my custom view. My Custom view was loaded fine as expected but button actions not fired if enable ARC for CustomView.m file, If I disable ARC then Button actions are firing…
Where Im going wrong..
Is it the correct way of loading a nib of uiview (which i want to use in many places in my project..)
Thank you ..
This is a very confusing/confused implementation of an
init
method.I'd suggest changing it to something like this...
Then changing your
ViewController
method to something like this...The problems you are having are possibly coming from the way you implemented the init method as an instance method but then ignored the instance and returned a new instance.
The memory implications of that are confusing and hard to work out.