我的自定义单元格未显示在表格视图中

时间:2019-06-17 02:59:12

标签: ios swift uitableview

所以我一直试图让我的自定义单元格显示在此表视图中,但是我不确定为什么它们不显示

我已经检查了其他堆栈溢出问题,并尝试对其进行了修复,但无济于事。请忽略aws的内容,因为您会看到我对文本进行了硬编码,所以现在我可以让它们出现。

这是持有表格视图的类中的代码

document.querySelector("td[data-name='nextDD2']").innerText  ='b';

这是QuestionCell类的代码

 import Foundation
 import AWSDynamoDB
 import AWSCognitoIdentityProvider
 import UIKit
// this will be the main feed class showing the user data 
class UserDetailTableViewController : UITableViewController {
// attributes for the custome cell

@IBOutlet weak var testing: UITextField!

@IBOutlet var Table: UITableView!
var response: AWSCognitoIdentityUserGetDetailsResponse?
var user: AWSCognitoIdentityUser?
var pool: AWSCognitoIdentityUserPool?
var questiondata : Array<Phototext> = Array()


override func viewDidLoad() {
    tableView.delegate = self
    tableView.dataSource = self

    super.viewDidLoad()

    self.pool = AWSCognitoIdentityUserPool(forKey: AWSCognitoUserPoolsSignInProviderKey)
    if (self.user == nil) {
        self.user = self.pool?.currentUser()

    }
         // grabbing data from our aws table
    updateData()

    self.refresh()


}



override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.setToolbarHidden(true, animated: true)
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.setToolbarHidden(false, animated: true)
}


@IBAction func Questions(_ sender: Any) {
    performSegue(withIdentifier: "ask", sender: self)
}


// MARK: - IBActions

@IBAction func signOut(_ sender: AnyObject) {
    self.user?.signOut()
    self.title = nil
    self.response = nil
    self.refresh()
}

 // reloads the prior view
 func refresh() {
    self.user?.getDetails().continueOnSuccessWith { (task) ->    
 AnyObject? in
        DispatchQueue.main.async(execute: {
            self.response = task.result
            self.title = self.user?.username
            // saving the user name from the main menu 
            username123 = self.user?.username! ?? "broken"
        })
        return nil
    }


  }
    // function that calls to our aws dynamodb to grab data from the    
     // user     
    //and re update questions
     // the array list

   func updateData(){
    let scanExpression = AWSDynamoDBScanExpression()
    scanExpression.limit = 20
    // testing to grabt the table data upon startup
    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.default()
    dynamoDBObjectMapper.scan(Phototext.self, expression:     
  scanExpression).continueWith(block: {    
   (task:AWSTask<AWSDynamoDBPaginatedOutput>!) -> Any? in
        if let error = task.error as NSError? {
            print("The request failed. Error: \(error)")
        } else if let paginatedOutput = task.result {
            // passes down an array of object
            for Photo in paginatedOutput.items as! [Phototext] {
                // loading in the arraylist of objects
                // adding the objects to an arraylist
                self.questiondata.append(Photo)




            }

            DispatchQueue.main.async {
                //code for updating the UI

            }

        }

        return ()

    })

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // returning the number of rows
        return 3
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath:     
  IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: 
     "Questionpost", for: indexPath) as! QuestionCell

        cell.QuestionText.text = "call it"
        cell.Subject.text = "a day"

        return cell


    }


}

}

单元格类称为QuestionCell,我在情节提要中的单元格上留下的标识符是Questionpost

这是我的故事板的照片: enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

我已经通过声明具有正确类型的扩展名来修复了该问题。

extension UserDetailTableViewController: UITableViewDataSource,UITableViewDelegate{


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // returning the number of rows
    return 3
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Questionpost", for: indexPath) as! QuestionCell

    cell.QuestionText.text = "call it"
    cell.Subject.text = "a day"

    return cell


}}

关于正在发生的事情的很好的解释,嵌入表视图时需要符合UITableViewDataSource和UITableViewDelegate。

Redundant conformance of TableView to protocol UITableViewDataSource with Xib Files

相关问题