简体   繁体   English

静态分组表视图单元格

[英]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. 我还创建了一个“ SettingsTableViewController.swift”类,并将其附加到该视图。

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. 如果我未附加“ SettingsTableViewController.swift”文件,则它将显示静态分组的单元格。

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: 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. 您已经从情节提要中定义了节和行的数量,然后使用代码将其覆盖为0 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 你返回0行的多数民众赞成在导致问题做类似

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

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

      return 1 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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