我正在尝试使用代码“即时”创建一个按钮,并且我希望该按钮执行
继续到不同的控制器。据我所知,以编程方式创建segue是不可能的,但是如果创建的按钮不在我的故事板上,我该如何通过呢?
这是创建按钮的代码:
- (void)addButton:(UIView*)view inLocation:(CGPoint)point
{
UIButton *but=[UIButton buttonWithType:UIButtonTypeRoundedRect];
but.frame= CGRectMake(point.x, point.y,30,30);
[but setTitle:@"CHOOSE" forState:UIControlStateNormal];
// The nilSymbol should call a method that will perform the segue
[but addTarget:self action:@selector(nilSymbol) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:but];
}
有什么选择可以做到这一点吗?
在 Interface Builder 中,创建一个 segue。
由于您无法将 Segue 连接到按钮(它还不存在),因此只需将 Segue 连接到启动 ViewController 即可。
然后,当您创建按钮时:
// ....
[but addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
// ....
在 someMethod 中:
-(void)someMethod
{
[self performSegueWithIdentifier:@"segueIdentifier" sender:self];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)