在我的main.Storyboard上,我有一个TableViewController,它被设置为一个带有TableViewController.swift的自定义类。自定义TableView函数没有被调用?
swift文件具有定义的所有tableview函数和连接的UITableView的@IBOutlet。定义的类是UINavigationController,UITableViewDelegate。这个viewController是通过prepareForSegue函数从secondViewController调用的。
我还创建了CustomCell.swift类UITableViewCell和所有@IBOutlet的标签在我的UITableViewCell已被设置为customCell类。
我无法粘贴我所有的代码,但如果您需要查看任何特定的代码,请告诉我,我很乐意发布。
构建成功,应用程序运行,但tableviewcells不显示,并且没有任何tableview函数被调用。我看到2个Flash动画屏幕 - 表示tableviewcell可能有2个视图 - 但无法确定我应该检查的位置?
//下面是SEGUE触发功能的TableViewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//print("In prepareswgue: ",segue, " ",sender)
if(segue.identifier == "resultSegue")
{
let nav = segue.destinationViewController as! UINavigationController
let svc = nav.topViewController as! TableViewController
svc.serialNo = self.TSSerialNoField.text
}
}
//Below is the custom TableVIewController class code
class TableViewController: UINavigationController,UITableViewDataSource, UITableViewDelegate
{
var serialNo:String!
var ashHardwareData: NSMutableArray!
@IBOutlet var ResultTableView: UITableView!
//@IBOutlet weak var LogCaseButton: UIButton!
@IBOutlet weak var TypeResultLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.ResultTableView?.allowsSelectionDuringEditing = true
self.ResultTableView?.delegate = self
ResultTableView?.dataSource = self
}
override func viewDidAppear(animated: Bool) {
self.getHardwareData(serialNo.uppercaseString)
}
/*override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
}*/
func getHardwareData(serialno:String)
{
ashHardwareData = NSMutableArray()
ashHardwareData = ModelManager.getInstance().getHardwareData(serialno)
ResultTableView?.reloadData()
}
//TableView Delegate Methods
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
print("In height func")
return 50
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print(ashHardwareData.count)
return ashHardwareData.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:ResultsCell = tableView.dequeueReusableCellWithIdentifier("results", forIndexPath: indexPath) as! ResultsCell
let hardware:HardwareInfo = ashHardwareData.objectAtIndex(indexPath.row) as! HardwareInfo
let contract:ContractInfo = ashHardwareData.objectAtIndex(indexPath.row) as! ContractInfo
cell.SNOLabel.text = "Serial N0: \(hardware.SerialNo)"
cell.ContractIDLabel.text = "Contract ID: \(contract.ContractID)"
cell.OrgLabel.text = "Organisation: \(hardware.Organisation)"
cell.ModelLabel.text = "Model: \(hardware.Model)"
if(contract.DaystoExpiry > 0) {
cell.TypeLabel.text = "Contract Type: Active"
self.TypeResultLabel.hidden = false
self.TypeResultLabel.text = "To log a technical case for the Hardware please click on Log Technical Case button."
cell.LogCaseButton.hidden = false
cell.LogCaseButton.tag = indexPath.row
}
else {
cell.TypeLabel.text = "Contract Type: Expired"
cell.LogCaseButton.hidden = true
self.TypeResultLabel.hidden = false
self.TypeResultLabel.text = "Support Contract for the hardware expired. Please contact Sales team to renew the contract."
}
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//here is the code for the ResultsCell custom UITableViewCell
import Foundation
import UIKit
class ResultsCell: UITableViewCell {
@IBOutlet weak var SNOLabel: UILabel!
@IBOutlet weak var LogCaseButton: UIButton!
@IBOutlet weak var ContractIDLabel: UILabel!
@IBOutlet weak var OrgLabel: UILabel!
@IBOutlet weak var TypeLabel: UILabel!
@IBOutlet weak var ModelLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
你需要发布一些代码,否则很难说出什么问题。 –
我用代码修改了问题。如果你需要更多的话让我知道。感谢您的快速回复 – Ashley
为什么你的'TableViewController'扩展了'UINavigationController'?为什么不'UIViewController'甚至是'UITableViewController'? – rmaddy