Ios 如何在Swift 3中使用可扩展的TableView或手风琴
我是ios新手。 我想制作一个带有可扩展菜单的导航抽屉。我该怎么做。 我没有导航抽屉,但现在想在抽屉中添加子菜单,但我不知道如何做,请帮助。先谢谢你 这是我的Ios 如何在Swift 3中使用可扩展的TableView或手风琴,ios,swift,Ios,Swift,我是ios新手。 我想制作一个带有可扩展菜单的导航抽屉。我该怎么做。 我没有导航抽屉,但现在想在抽屉中添加子菜单,但我不知道如何做,请帮助。先谢谢你 这是我的DrawerViewController class LeftSideViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate { var menuItems:[String] = ["Main","Project","Client","User
DrawerViewController
class LeftSideViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate {
var menuItems:[String] = ["Main","Project","Client","User","About","Logout"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return menuItems.count;
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let mycell = tableView.dequeueReusableCell(withIdentifier: "MenuItemCell", for: indexPath) as! MyCustomTableViewCell
mycell.labelMenuItem.text = menuItems[indexPath.row]
return mycell;
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
switch (indexPath.row) {
case 0:
let centerViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
let centerNavController = UINavigationController(rootViewController: centerViewController)
let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.centerContainer!.centerViewController = centerNavController
appDelegate.centerContainer!.toggle(MMDrawerSide.left, animated: true, completion: nil)
break;
case 1:
let aboutViewController = self.storyboard?.instantiateViewController(withIdentifier: "AboutViewController") as! AboutViewController
let aboutNavController = UINavigationController(rootViewController: aboutViewController)
let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.centerContainer!.centerViewController = aboutNavController
appDelegate.centerContainer!.toggle(MMDrawerSide.left, animated: true, completion: nil)
break;
default:
print("\(menuItems[indexPath.row]) is selected")
}
}
我有“项目”的子菜单,如添加项目、编辑项目、删除项目。
当用户单击Project时,我会显示此子菜单,如手风琴,
当用户单击任何子菜单(添加、编辑或删除)时,它将在新的
ViewController
中打开。对不起,我有点困惑。我分配了这个变量子菜单项:[String]=[“添加”、“更新”、“删除”]var menuToShow:[String]=开关大小写中的菜单项,因为每个子菜单都不同。但我如何附加它们?我能做些什么使它们可折叠?在单击特定行时,您会将子菜单项指定给MenuTo show,并使用我已经提到的动画重新加载部分。它与可折叠略有不同,但我认为它是比可折叠更好的选择。为什么要使用switch语句,不需要这样做。仅将菜单项分配给菜单,以便在ViewDidLoad中显示,并在选择行后将子菜单分配给菜单。
@IBOutlet var tblViewMenu: UITableView!
var menuItems : NSMutableArray = ["dash","case","client"]
var subMenu : NSMutableArray = ["1","2"]
var menuToShow : NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
menuToShow = menuItems
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menuToShow.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell")!
let lblName : UILabel = cell.viewWithTag(1) as! UILabel
lblName.text = menuToShow.objectAtIndex(indexPath.row) as? String
return cell;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
menuToShow = subMenu
tableView.reloadSections(NSIndexSet.init(index: 0), withRowAnimation: UITableViewRowAnimation.Fade)
}