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给出了底部表单样式弹出窗口的示例
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)
})