gpt4 book ai didi

ios - Swift - TableView 未填充数据但未显示任何错误

转载 作者:行者123 更新时间:2023-11-29 00:50:51 24 4
gpt4 key购买 nike

使用以下教程,我尝试显示一些将填充在表格中的股票信息。我已经创建了 TableView Controller 和 TableView 单元格,并将 stockTableViewCell 与 TableView 单元格链接起来。但是,我无法将主 Storyboard 上的表格 View 与自定义表格 View Controller 链接起来。

基本上,每次我尝试将其输入自定义类字段时,它都不适用,当我离开时,它就会消失

我的问题是,我的 View Controller 或 TableView 单元格是否有问题,或者我的 Storyboard中是否存在我配置错误的内容?

教程:https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson7.html

表格 View Controller

import UIKit

class stocksTableViewController: UITableViewController{

// Mark: Properties

var stocks = [stockData]()
let stock = stockinfo()

override func viewDidLoad() {
super.viewDidLoad()
loadSampleStockData()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func loadSampleStockData () {

var stock1: stockData = stockData(name: "", askPrice: "", percentageChange: "", stockTicker: "")
var stock2: stockData = stockData(name: "", askPrice: "", percentageChange: "", stockTicker: "")
var stock3: stockData = stockData(name: "", askPrice: "", percentageChange: "", stockTicker: "")

stock.getInfo("FB") {(name, price, change) in dispatch_async(dispatch_get_main_queue(),{
stock1 = stockData(name: name, askPrice: price, percentageChange: change, stockTicker: "FB")})
}

stock.getInfo("MSFT") {(name, price, change) in dispatch_async(dispatch_get_main_queue(),{
stock2 = stockData(name: name, askPrice: price, percentageChange: change, stockTicker: "MSFT")})
}

stock.getInfo("APPL") {(name, price, change) in dispatch_async(dispatch_get_main_queue(),{
stock3 = stockData(name: name, askPrice: price, percentageChange: change, stockTicker: "APPL")})
}

stocks += [stock1, stock2, stock3]
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return stocks.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cellIdentifier = "stockViewCell"

let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! stockTableViewCell

let stock = stocks[indexPath.row]

cell.stockName.text = stock.name
cell.stockPercentage.text = stock.percentageChange
cell.stockDollarChange.text = stock.askPrice
cell.stockTicker.text = stock.stockTicker

return cell
}
}

表格 View 单元格

import Foundation
import UIKit

class stockTableViewCell: UITableViewCell {

// Properties

@IBOutlet weak var stockTicker: UILabel!
@IBOutlet weak var stockPercentage: UILabel!
@IBOutlet weak var stockName: UILabel!
@IBOutlet weak var stockDollarChange: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization Code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}

最佳答案

您实际上需要在 viewDidLoad() 中注册自定义的tableviewcell

此外您还可以查看以下链接

http://www.mysamplecode.com/2013/06/ios-custom-uitableviewcell-example.html

关于ios - Swift - TableView 未填充数据但未显示任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com