我正在创建一个按钮并将其添加到我的toolBar中,如下所示:
UIButton *sendButtzon = [UIButton buttonWithType:UIButtonTypeRoundedRect];
sendButtzon.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[sendButtzon setTitle:@"More" forState:UIControlStateNormal];
sendButtzon.frame = CGRectMake(toolBar.bounds.size.width - 18.0f,
6.0f,
58.0f,
29.0f);
[toolBar addSubview:sendButtzon];
如何打开一个新的viewController(我有一个名为“MoreView”的segue)?
答案 0 :(得分:3)
您实施以下操作方法:
-(void)buttonPressed:(UIButton*)sender
{
[self performSegueWithIdentifier:@"MoreView" sender:sender];
}
并将此链接与您的按钮相关联(将此行添加到您问题中的代码):
[sendButtzon addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
这会导致按下该按钮以调用buttobPressed:
方法,该方法将执行您在故事板中定义的segue。
答案 1 :(得分:0)
为此,您必须在故事板中定义名为“MoreView”的segue。
否则你必须按下这个按钮创建UIViewControler ..
-(void)buttonPressed:(UIButton*)sender
{
UIViewController *destinationController = [[UIViewController alloc] init];
[self presentModalViewContrller:destinationController animated:YES];
}
或创建视图控制器表单故事板。
-(void)buttonPressed:(UIButton*)sender
{
UIViewController *destinationController = [self.storyboard instantiateViewContrllerWithIdentifier:@"DestinationViewController "];
[self presentModalViewContrller:destinationController animated:YES];
}
每个UIViewController故事板都有属性。