我正在创建一个按钮,并将其添加到我的工具栏中,如下所示:

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”的名称)?

最佳答案

您实现以下操作方法:

-(void)buttonPressed:(UIButton*)sender
{
    [self performSegueWithIdentifier:@"MoreView" sender:sender];
}


然后像这样将其链接到您的按钮(将此行添加到您问题中的代码中):

[sendButtzon addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];


这将导致点击按钮以调用buttobPressed:方法,该方法反过来执行您在情节提要中定义的segue。

关于iphone - ios从编程创建的按钮segue打开模态?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18033256/

10-10 03:30