Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios STPOPP如何在Swift中初始化?_Ios_Swift - Fatal编程技术网

Ios STPOPP如何在Swift中初始化?

Ios STPOPP如何在Swift中初始化?,ios,swift,Ios,Swift,我在玩这个。它说我必须用代码初始化它 STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:[ViewController new]]; [popupController presentInViewController:self]; 我尝试用以下代码实现这一点(HelpersNear是UIViewController的名称) 但作为响应,我得到了编译错误,它让我从构造

我在玩这个。它说我必须用代码初始化它

STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:[ViewController new]];
[popupController presentInViewController:self];
我尝试用以下代码实现这一点(HelpersNear是UIViewController的名称)

但作为响应,我得到了编译错误,它让我从构造函数中删除
rootViewController
。在我删除它之后,我得到另一个错误

我做错了什么?

请尝试以下代码:

var popup = STPopupController(rootViewController: HelpersNear())
popup.presentInViewController(self)
例如:

class FooViewController: UIViewController {  
  let name: String

  init() {
    name = "Bar"
    super.init(nibName: nil, bundle:nil)
  }

  required init(coder: NSCoder) {
    super.init(coder: coder)
  }
}

在Swift中使用此库很简单。 下面我使用STPOUPCONTROLLER给出了底部表单样式弹出窗口的示例

  • 在脚本中创建UIViewController或UITableViewController(您可以使用github上提供的STPOUP库的示例项目(STPOUPExample)中完成的示例)

  • 将视图控制器的脚本id设置为f.ex.:
    MultiselectionTableViewController

  • 要显示此弹出视图,请使用以下代码:

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("MultiselectionTableViewController") as! MultiselectionTableViewController
        vc.title = "Choose your options"
        vc.items = ["First element", "Second element", "Third element"]
        vc.delegate = self
    
        let popup = STPopupController(rootViewController: vc)
        popup.style = STPopupStyle.BottomSheet
    
        dispatch_async(dispatch_get_main_queue(), { 
    
            popup.presentInViewController(self.parentViewController)
        })
    
  • dispatch\u async
    块内显示弹出窗口非常重要。它可以防止在显示新视图控制器时出现延迟


  • 您的
    HelpersNear
    视图控制器未实例化。
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("MultiselectionTableViewController") as! MultiselectionTableViewController
        vc.title = "Choose your options"
        vc.items = ["First element", "Second element", "Third element"]
        vc.delegate = self
    
        let popup = STPopupController(rootViewController: vc)
        popup.style = STPopupStyle.BottomSheet
    
        dispatch_async(dispatch_get_main_queue(), { 
    
            popup.presentInViewController(self.parentViewController)
        })