I have programatically added a UIButton
, for which I require addTarget
. The selector action is in another class. I have used the following code to do this.
UIButton *homeBtn = [[UIButton alloc] initWithFrame:CGRectMake(10,5,32,32)];
homeBtn.backgroundColor = [UIColor greenColor];
[homeBtn addTarget:[myClass class] action:@selector(ButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubView:homeBtn];
+(void)ButtonTapped:(id)sender{
NSLog(@"here");
}
This works just fine. But I need to use pushViewController
in the class function for which I need to pass the self.navigationController
to the function.
I tried using homeBtn.nav = self.navigationController;
but this gives an error 'Property nav not found on object of type UIButton *'
Can anyone please help me and tell me how to pass the self.navigationController
to the class function.
Regards,
Neha