在我的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