Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have already made a tableview with tableview controller but I am really in need to know how to do the same thing with a custom sized tableview inside a view controller. my concern is only about inserting data because I need to have sections in it.

What I have tried:

I tried with tableview controller but apparently it is a bit different with tableview
Posted
Updated 28-Nov-18 2:07am

1 solution

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
    
    var menu: Array = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

          menu = ["home", "Logout"]
    }

 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menu.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: TableViewCell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell 
        cell.labelmanu.text = menu[indexPath.row]
        return cell
    }


Use the array to declare your data in tableview and delegates and datasource method to update and set the data accordingly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900