2015-10-22 30 views

回答

1

我不明白你用按钮做什么。我和我的团队通常使用表单元格,就像菜单项一样。像这样的例子

enter image description here

enter image description here

  • 我定义了一个菜单项数组

    var menuItems = ["Sign in", "My abc", "My def"]

  • 与代码功能标志,删除 “登录”,并添加“我的帐户”。在我简单的例子,我用didSelectRowAtIndex并勾选“登录”菜单

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    
    // sign in item 
        if indexPath.row == 0 && menuItems[0] == "Sign in" { 
    
         let alert = UIAlertController(title: "Signing in", message: "Press OK to sign in", preferredStyle: .Alert) 
    
         alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)) 
    
         alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in 
    
          self.menuItems.removeAtIndex(0) 
          self.menuItems.insert("My Account", atIndex: 0) 
    
          tableView.reloadData() 
         })) 
    
         presentViewController(alert, animated: true, completion: nil) 
    
         } 
        } 
    

希望这有助于。

+0

谢谢你解决我的问题 –

相关问题