UIMenuController没有显示菜单

UIMenuController没有显示菜单,第1张

UIMenuController没有显示菜单
//View controller class which is implementing TableViewCellDelegate//Make sure you do followng//subclass UITableViewCell using class name TableViewCell which has delegate//you link UITableViewCell in ViewController class with TableViewCell in Custom Class column in interface builder(storyboard)//In TableViewCell cell identifier you give name as Cell.class ViewController: UITableViewController,TableViewCellDelegate {    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.    }// tableview delegates  override  func numberOfSectionsInTableView(tableView: UITableView) -> Int // Default is 1 if not    {        return 1;    }    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {        return 10    }     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell     {        var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? TableViewCell        if cell == nil { cell = TableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")        }        cell?.delegate=self;        cell?.textLabel?.text="Cell text"        return cell!    }     func tableCellSelected(tableCell: UITableViewCell)     {        var longprss : UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: Selector("display:"))        tableCell.addGestureRecognizer(longprss)     }    //end tableview delegate    // menu delegates    override func canBecomeFirstResponder() -> Bool {        return true    }    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool    {        println(action);        if(action == Selector("deleteLine:") || action == Selector("editRow:"))        { return true;        }        else        { return false;        }    }    func deleteLine(sender: AnyObject?) {        println("delete line")    }    func editRow(sender: AnyObject?) {        println("edit row");    }    //end menu delegate    //action handler of longPressGesture    func display(gesture: UILongPressGestureRecognizer)    {        gesture.view?.becomeFirstResponder()        println("Is first responder")        var menu = UIMenuController.sharedMenuController()        var deleteItem = UIMenuItem(title: "Delete", action: Selector("deleteLine:"))        var editItems = UIMenuItem(title: "Edit", action: Selector("editRow:"))        menu.menuItems = [deleteItem ,editItems]        menu.setTargetRect(CGRect(x: 30, y: 8, width: 100, height: 50), inView: gesture.view!)        menu.setMenuVisible(true, animated: true)    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }}//This is subclass of UITableViewCellprotocol TableViewCellDelegate{    func tableCellSelected( var tableCell : UITableViewCell)}class TableViewCell: UITableViewCell {    var delegate : TableViewCellDelegate?    override func awakeFromNib() {        super.awakeFromNib()        // Initialization pre    }    override func setSelected(selected: Bool, animated: Bool) {        super.setSelected(selected, animated: animated)        if((self.delegate) != nil)        { delegate?.tableCellSelected(self);        }        // Configure the view for the selected state    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4908823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存