最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

[已解决]swift中实现弹出列表窗口

Swift crifan 104浏览 0评论

需要实现类似于这种:

swift popup action list

xcode – Swift alert view (iOS8) with OK and cancel button, which button tapped – Stack Overflow

用了:

                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let cancelAlertAction = UIAlertAction(title: "复制", style: UIAlertActionStyle.Default, handler: copyMessageHandler)
                        actionsAlertController.addAction(cancelAlertAction)
                        let sureAlertAction = UIAlertAction(title: "搜藏", style: UIAlertActionStyle.Destructive, handler: addFavoriteMessageHandler)
                        actionsAlertController.addAction(sureAlertAction)
                        self.presentViewController(actionsAlertController, animated: true, completion: nil)
    func copyMessageHandler(alerAction:UIAlertAction){
        print("copyMessageHandler alerAction=\(alerAction)")
    }
   
    func addFavoriteMessageHandler(alerAction:UIAlertAction){
        print("addFavoriteMessageHandler alerAction=\(alerAction)")
    }

结果显示在最底下了:

换成:

//                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.Alert)

结果:

swift popup window center

swift popup window screen center

ios – how to center a popoverview in swift – Stack Overflow

swift UIAlertController position

ios – How to position a UIAlertController’s view? – Stack Overflow

ios – How to display activity indicator in center of UIAlertController? – Stack Overflow

代码:

//                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.Alert)
                        let cancelAlertAction = UIAlertAction(title: "复制", style: UIAlertActionStyle.Default, handler: copyHandler)
                        actionsAlertController.addAction(cancelAlertAction)
                        let sureAlertAction = UIAlertAction(title: "搜藏", style: UIAlertActionStyle.Default, handler: addFavoriteHandler)
                        actionsAlertController.addAction(sureAlertAction)
                        self.presentViewController(actionsAlertController, animated: true, completion: nil)

然后可以显示了:

但是:

[部分解决]swift中给回调函数添加参数

此处的action list是水平方式显示的

-》

抽空再去研究:如何让action list是垂直方式的列出来。

转载请注明:在路上 » [已解决]swift中实现弹出列表窗口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
21 queries in 0.216 seconds, using 9.82MB memory