【发布时间】:2014-03-19 07:48:14
【问题描述】:
我以编程方式添加了一个UIButton,为此我需要addTarget。选择器操作在另一个类中。我已经使用以下代码来执行此操作。
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");
}
这很好用。但我需要在需要将self.navigationController 传递给函数的类函数中使用pushViewController。
我尝试使用homeBtn.nav = self.navigationController;
但这会产生错误'Property nav not found on object of type UIButton *'
谁能帮助我,告诉我如何将self.navigationController 传递给类函数。
问候,
内哈
【问题讨论】:
标签: ios objective-c