简体   繁体   中英

Static Grouped table View cells

I am trying to create a table view with static grouped cells. See image below:

在此处输入图片说明

I also create a "SettingsTableViewController.swift" class and attached it to this view.

But when I run the app the table view comes blank. If I unattached the "SettingsTableViewController.swift" files then it shows the static grouped cells.

On app build the screen is below:

在此处输入图片说明

One more thing to point out is that I am manually transitioning from one segue to another by using the following code:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("accountSettings") as! SettingsTableViewController
    var fullname: AnyObject = self.username
    var job: AnyObject = self.jobTitle
    vc.username = fullname
    vc.jobTitle = job
    self.presentViewController(vc, animated: true, completion: nil)

Code of SettingsTableViewController:

import UIKit

class SettingsTableViewController: UITableViewController {

var username:AnyObject = ""
var jobTitle:AnyObject = ""

@IBOutlet weak var name: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

   name.text? = username as! String
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return 0
}

 }

Can anyone help me?

Thanks.

You have already defined your number of sections and rows from storyboard and then you are overriding it as 0 using code. That is why your tableview is displayed as blank screen. To get it working, Remove these methods :

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

  return 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

  return 0
}

u returning 0 no of row thats cause the problem do something like

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int 
{

      return 1 
} 
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{

      return 1 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM