2016-11-22 4 views
0

私はiosを新しくしました。 拡張可能なメニューでナビゲーション用の引き出しを作りたいのですがどうすればいいですか? 私はナビゲーション引き出しをしましたが、今では引き出しにサブメニューを追加したいのですが、どうしたらいいか教えてください。前もって感謝します。Swift 3で拡張可能なTableViewまたはアコーディオンの使い方

は、ここで私は、このようなプロジェクト、編集プロジェクトの追加、プロジェクトを削除するなど、「プロジェクト」のためのサブメニューを持っている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が開きます。

答えて

0
@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) 
} 
+0

申し訳ありませんが、私は少し混乱しています。私はこのvar subMenuItemsを割り当てました:[文字列] = ["Add"、 "Update"、 "Delete"] var menuToShow:[String] =メニュー項目はスイッチケースにあります。どうすればそれらを追加できますか? – Pratik

+0

折り畳み可能にするにはどうすればよいですか? – Pratik

+0

をクリックすると、その時点でMenuModeにsubMenuItemsを割り当てて、前述のアニメーションでセクションを表示してリロードします。 –

関連する問題