簡體   English   中英

我的自定義單元格沒有顯示在我的 tableview 中

[英]My custom cells are not showing up in my tableview

所以我一直試圖讓我的自定義單元格顯示在這個 tableview 上,但我不確定為什么它們沒有顯示出來

我已經檢查了其他堆棧溢出問題並嘗試了他們的修復,但無濟於事。 請忽略 aws 內容,因為您可以看到我對文本進行了硬編碼,因此我現在可以讓它們出現。

這是包含 tableview 的類中的代碼

 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 類的代碼

import UIKit

class QuestionCell: UITableViewCell {

@IBOutlet weak var Subject: UILabel!

@IBOutlet weak var QuestionText: UITextView!

 }

單元格類稱為 QuestionCell ,我在故事板中的單元格上留下的標識符是 Questionpost

這是我的故事板的照片: 在此處輸入圖片說明

在此處輸入圖片說明

我通過聲明具有正確類型的擴展來修復它。

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


}}

很好地解釋了正在發生的事情,當您嵌入 tableview 時,您需要符合 UITableViewDataSource 和 UITableViewDelegate 。

TableView 與協議 UITableViewDataSource 與 Xib 文件的冗余一致性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM