iOS-如何在UITableView的单元格上方添加带有文本/按钮的气泡? [英] iOS - How to add bubble with text/buttons over cell in UITableView?

查看:70
本文介绍了iOS-如何在UITableView的单元格上方添加带有文本/按钮的气泡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何调用此功能,音乐应用程序的最高支持为8.4,看起来就像屏幕截图所示.我想在我的应用程序中实现它,因此当用户按下单元格时,将显示带有2个选项按钮的气泡".我对如何在Obj-C中实现它感兴趣,但是我相信人们会赞赏Swift编写的答案.谢谢

我正在做的是创建一个viewController作为弹出窗口(PopoverMenuController),并添加一个tableView作为菜单的子视图.同样,您可以添加所需的任何UI控件来代替tableView.

这是您使用我的PopoverMenuController的方式.

  var myPopupMenu:PopoverMenuController!覆盖func tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath){//使单元格完全可见让tableCell = tableView.cellForRow(at:indexPath)!tableView.scrollRectToVisible(tableView.rectForRow(at:indexPath),动画:false)//弹出菜单myPopupMenu = PopoverMenuController()myPopupMenu.sourceView = tableCellvar rect = tableCell.bounds//我正在稍微调整弹出菜单的位置(这是可选的)rect.origin.y = rect.size.height/3.0rect.size.height = rect.size.height/2.0myPopupMenu.sourceRect =矩形myPopupMenu.addAction(PopMenuAction(textLabel:"MyMenu-1",annexType:.none,处理程序:myMenuHandler1))myPopupMenu.addAction(PopMenuAction(textLabel:"MyMenu-2",annexType:.none,处理程序:myMenuHandler2))目前(myPopupMenu,动画:true,完成:nil)}func myMenuHandler1(_ action:PopMenuAction?)->布尔{//做一些工作...返回假}func myMenuHandler2(_ action:PopMenuAction?)->布尔{//做一些工作...返回假} 

转化为Obj-C应该不是一件大事.我在此处放置了PopoverMenuController.swift的源代码.该控制器是独立的,并且具有使用说明.

希望这会有所帮助.

I really have no idea how to call this feature, music app had it up to 8.4, it looks like on the screenshot. I want to implement it in my app so when user presses the cell the "bubble" with 2 option buttons shows up. I am interested in how to make it happen in Obj-C but I'm sure people will apreciate the answer written in Swift. Thanks Screenshot

解决方案

I'm doing exactly the same thing as what you want. To do so, you have to create your own view controller, not UIMenuItem. The screen capture is as follows.

What I'm doing is to create a viewController as popup (PopoverMenuController), and adding a tableView as a subView for menu. In the same way, you can add whatever UI controls you want instead of tableView.

Here is how you use my PopoverMenuController.

var myPopupMenu: PopoverMenuController!

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // make cell fully visible
    let tableCell = tableView.cellForRow(at: indexPath)!
    tableView.scrollRectToVisible(tableView.rectForRow(at: indexPath), animated: false)
    // pop up menu
    myPopupMenu = PopoverMenuController()
    myPopupMenu.sourceView = tableCell
    var rect = tableCell.bounds
    // I'm adjusting popup menu position slightly (this is optional)
    rect.origin.y = rect.size.height/3.0
    rect.size.height = rect.size.height / 2.0
    myPopupMenu.sourceRect = rect
    myPopupMenu.addAction(PopMenuAction(textLabel: "MyMenu-1", accessoryType: .none, handler: myMenuHandler1))
    myPopupMenu.addAction(PopMenuAction(textLabel: "MyMenu-2", accessoryType: .none, handler: myMenuHandler2))
    present(myPopupMenu, animated: true, completion: nil)
}

func myMenuHandler1(_ action: PopMenuAction?) -> Bool {
    // do some work...
    return false
}

func myMenuHandler2(_ action: PopMenuAction?) -> Bool {
    // do some work...
    return false
}

To transltae to Obj-C should not be a big effort. I put souce code of PopoverMenuController.swift here. This controller is self-contained and it has a description on how to use.

Hope this helps.

这篇关于iOS-如何在UITableView的单元格上方添加带有文本/按钮的气泡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆