我编程式地添加了一个UIButton
,对此我需要addTarget
。选择器动作在另一个类中。我已经使用下面的代码来做到这一点。将self.navigationController作为addTarget中的参数传递给UIbutton
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");
}
这工作得很好。但我需要在类函数中使用pushViewController
,因此我需要将self.navigationController
传递给函数。
我尝试使用homeBtn.nav = self.navigationController;
但是这给出了一个错误'Property nav not found on object of type UIButton *'
任何人都可以请帮助我,告诉我如何将self.navigationController
传递给类函数。
问候,
NEHA
http://stackoverflow.com/questions/3716633/passing-parameters-on-button-actionselector –