最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Trying to make Transaction List View with Plaid API - Stack Overflow

programmeradmin2浏览0评论

I am working in Swift to try and make a list view that shows all the transactions connected from all the accounts using Plaid API. But when I run this I get nothing. I have tried several different things, but nothing is working.

import UIKit

class TransactionViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet var tableView: UITableView!
    let communicator = ServerCommunicator()
    var transactions: [Transaction] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Transactions"
        
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "TransactionCell")
        
        fetchTransactions()
    }
    
    private func fetchTransactions() {
        communicator.callMyServer(path: "/server/transactions/get", httpMethod: .get) { (result: Result<[Transaction], ServerCommunicator.Error>) in
            DispatchQueue.main.async {
                switch result {
                case .success(let fetchedTransactions):
                    print("Fetched transactions: \(fetchedTransactions)") // Debug: Print fetched transactions
                    self.transactions = fetchedTransactions
                    self.tableView.reloadData()
                case .failure(let error):
                    print("Failed to fetch transactions: \(error)") // Debug: Print error if fetch fails
                }
            }
        }
    }
    
    // MARK: - UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("Number of transactions: \(transactions.count)") // Debug: Print number of rows in the table
        return transactions.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TransactionCell", for: indexPath)
        let transaction = transactions[indexPath.row]
        
        // Debug: Print transaction data for each row
        print("Transaction at index \(indexPath.row): \(transaction.date), \(transaction.description), $\(transaction.amount)")
        
        cell.textLabel?.text = "\(transaction.date): \(transaction.description) - $\(transaction.amount)"
        cell.detailTextLabel?.text = transaction.accountName
        return cell
    }
}
发布评论

评论列表(0)

  1. 暂无评论